python-uv
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePython uv
Python uv
Overview
概述
uv is an extremely fast Python package and project manager written in Rust, designed to replace pip, pip-tools, pipx, poetry, pyenv, and virtualenv. It provides unified project management, dependency resolution, Python version management, and tool execution with 10-100x speed improvements over traditional tools.
Key capabilities: Project initialization, dependency locking and syncing, Python version management, PEP 723 inline script dependencies, ephemeral tool execution via , monorepo workspaces with shared lockfiles, and package building/publishing.
uvxWhen to use: Python project initialization, dependency management, virtual environments, Python version pinning, running scripts with inline dependencies, monorepo workspaces, tool execution, publishing packages.
When NOT to use: Non-Python projects, conda-managed scientific computing environments with system-level binary dependencies, projects locked to legacy -only workflows.
setup.pyuv是一款用Rust编写的极速Python包和项目管理器,旨在替代pip、pip-tools、pipx、poetry、pyenv和virtualenv。它提供统一的项目管理、依赖解析、Python版本管理和工具执行功能,速度比传统工具快10-100倍。
核心功能: 项目初始化、依赖锁定与同步、Python版本管理、PEP 723内联脚本依赖、通过执行临时工具、支持共享锁文件的单体仓库工作区,以及包构建与发布。
uvx适用场景: Python项目初始化、依赖管理、虚拟环境、Python版本固定、运行带内联依赖的脚本、单体仓库工作区、工具执行、包发布。
不适用场景: 非Python项目、使用conda管理且包含系统级二进制依赖的科学计算环境、仅依赖传统工作流的项目。
setup.pyQuick Reference
快速参考
| Pattern | Command / API | Key Points |
|---|---|---|
| Init project | | Creates |
| Init library | | Creates |
| Init script | | PEP 723 inline metadata script |
| Add dependency | | Adds to |
| Add dev dependency | | Adds to |
| Add group dependency | | Custom dependency groups |
| Add optional | | Optional extras for libraries |
| Remove dependency | | Removes from |
| Lock dependencies | | Creates/updates |
| Upgrade in lockfile | | Targeted dependency upgrade |
| Sync environment | | Installs locked dependencies into |
| Sync for CI | | Fails if lockfile is stale |
| Sync frozen | | Skips lockfile verification |
| Run command | | Runs in project virtual environment |
| Run script | | Supports PEP 723 inline dependencies |
| Run in package | | Workspace-specific execution |
| Install Python | | Downloads and manages Python versions |
| Pin Python | | Writes |
| List Pythons | | Shows available and installed versions |
| Run tool | | Ephemeral tool execution |
| Tool with plugins | | Ephemeral tool with extra packages |
| Install tool | | Persistent global tool install |
| Workspace | | Monorepo multi-package support |
| Build package | | Creates sdist and wheel in |
| Publish | | Uploads to PyPI with trusted publishing |
| Export deps | | Generate requirements.txt from lockfile |
| 模式 | 命令/API | 关键要点 |
|---|---|---|
| 初始化项目 | | 创建 |
| 初始化库 | | 创建带 |
| 初始化脚本 | | 生成PEP 723内联元数据脚本 |
| 添加依赖 | | 添加至 |
| 添加开发依赖 | | 添加至 |
| 添加组依赖 | | 自定义依赖组 |
| 添加可选依赖 | | 库的可选额外依赖 |
| 移除依赖 | | 从 |
| 锁定依赖 | | 创建/更新 |
| 升级指定依赖 | | 定向升级特定依赖 |
| 同步环境 | | 将锁定的依赖安装至 |
| CI环境同步 | | 若锁文件过期则同步失败 |
| 冻结同步 | | 跳过锁文件校验以加快构建 |
| 运行命令 | | 在项目虚拟环境中运行命令 |
| 运行脚本 | | 支持PEP 723内联依赖脚本 |
| 在指定包中运行 | | 工作区专属执行 |
| 安装Python版本 | | 下载并管理Python版本 |
| 固定Python版本 | | 写入 |
| 列出Python版本 | | 显示可用及已安装的版本 |
| 运行临时工具 | | 临时执行工具 |
| 运行带插件的工具 | | 临时执行带额外包的工具 |
| 安装全局工具 | | 持久化安装全局工具 |
| 工作区配置 | | 单体仓库多包支持 |
| 构建包 | | 在 |
| 发布包 | | 通过可信发布方式上传至PyPI |
| 导出依赖 | | 从锁文件生成requirements.txt文件 |
Common Mistakes
常见错误
| Mistake | Correct Pattern |
|---|---|
Using | |
Activating venv manually before | |
Committing | Add |
Not committing | Always commit |
Using | |
Running | Only upgrade intentionally, use |
Mixing | Choose one tool for the project consistently |
Using | Use |
Forgetting | |
| Creating venv manually in uv project | |
Using | Use |
Not using | |
| 错误操作 | 正确做法 |
|---|---|
在uv项目中使用 | 使用 |
在执行 | |
将 | 将 |
未提交 | 务必提交 |
在CI环境中使用 | |
常规性执行 | 仅在需要时升级,使用 |
混合使用 | 为项目统一选择一种工具 |
使用 | 对受管理的项目使用 |
Docker构建时忘记使用 | |
| 在uv项目中手动创建虚拟环境 | |
新项目使用 | 使用 |
库项目未使用 | |
Delegation
任务委托
- Project scaffolding: Use agent
Explore - Dependency audit: Use agent
Task - Code review: Delegate to agent
code-reviewer
If theskill is available, delegate containerization patterns to it. If thedockerskill is available, delegate CI/CD pipeline configuration to it. If thegithub-actionsskill is available, delegate API testing patterns to it. If theapi-testingskill is available, delegate error monitoring setup to it. If thesentry-setup-loggingskill is available, delegate Node.js logging patterns to it (Python equivalent covered here with structlog).pino-logging
- 项目脚手架搭建:使用agent
Explore - 依赖审计:使用agent
Task - 代码审查:委托给agent
code-reviewer
若技能可用,将容器化模式委托给该技能处理。 若docker技能可用,将CI/CD流水线配置委托给该技能处理。 若github-actions技能可用,将API测试模式委托给该技能处理。 若api-testing技能可用,将错误监控设置委托给该技能处理。 若sentry-setup-logging技能可用,将Node.js日志模式委托给该技能处理(Python等效方案在此处通过structlog覆盖)。pino-logging
References
参考资料
- Project management and pyproject.toml configuration
- Dependency management, lockfiles, and groups
- Python version management and virtual environments
- Scripts, inline dependencies, and tool management
- Workspace support for monorepos
- FastAPI web framework patterns
- Pydantic validation and data modeling
- Async patterns with asyncio
- Type checking with mypy and pyright
- Testing with pytest
- Logging with structlog
- CLI applications with typer
- Docker integration and publishing
- 项目管理与pyproject.toml配置
- 依赖管理、锁文件与依赖组
- Python版本管理与虚拟环境
- 脚本、内联依赖与工具管理
- 单体仓库工作区支持
- FastAPI Web框架模式
- Pydantic验证与数据建模
- 基于asyncio的异步模式
- 使用mypy和pyright进行类型检查
- 使用pytest进行测试
- 使用structlog进行日志管理
- 使用typer开发CLI应用
- Docker集成与包发布