uv cheatsheet
Manage python version (replaces pyenv)
| Purpose | Command |
|---|---|
| Install a specific Python version | uv python install <version> |
| List available Python versions | uv python list |
| Use a specific Python version in a project | uv python use <version> |
| Automatically install the required Python version | uv run --python <version> script.py |
| Pin the Python version for a project | uv python pin |
Manage environment (replaces venv)
| Purpose | Command |
|---|---|
| Create a virtual environment | uv venv |
| Create a virtual environment with specific Python ver. | uv venv --python <version> |
| Activate virtual environment (Linux/macOS) | source .venv/bin/activate |
| Activate virtual environment (Windows) | .venv\Scripts\activate |
| Remove a virtual environment | uv remove |
| Reinstall all dependencies in the virtual environment | uv sync --reinstall |
Manage project (replaces poetry)
| Purpose | Command |
|---|---|
| Initialize a new project | uv init <project-name> |
| Add a package as a dependency | uv add <package-name> |
| Add a dev dependency | uv add --dev <package-name> |
| Add a package from Git | uv add git+https://github.com/user/repo.git |
| Remove a package | uv remove <package-name> |
| Lock dependencies to exact versions | uv lock |
Upgrade a specific package only on uv.lock | uv lock --upgrade-package <package-name> |
Upgrade all dependencies only on uv.lock | uv lock --upgrade |
| Build a Python package | uv build |
| Publish a package to PyPI | uv publish |
Manage packages (replaces pip, pipx)
| Purpose | Command |
|---|---|
| Install a package | uv add <package-name> |
| Remove a package | uv remove <package-name> |
| Install dependencies from pyproject.toml | uv sync |
| Install dependencies while excluding some groups | uv sync --no-group dev --no-group lint |
| Install dependencies from requirements.txt | uv pip install -r requirements.txt |
| Freeze dependencies into requirements.txt | uv pip freeze > requirements.txt |
| Generate requirements.txt from uv.lock | uv export --format requirements-txt > requirements.txt |
Upgrade only the uv.lock file | uv lock --upgrade |
Upgrade all packages (uv.lock and execution) | uv sync --upgrade |
Upgrade a single package (uv.lock and execution) | uv sync --upgrade-package <package-name> |
| Install CLI tools globally | uv tool install <tool-name> |
| List all installed tools | uv tool list |
| Remove a globally installed CLI tool | uv tool uninstall <tool-name> |
| Upgrade all installed CLI tools | uv tool upgrade --all |
Manage scripts (replaces python tools)
| Purpose | Command |
|---|---|
| Run a Python script inside the virtual environment | uv run <script.py> |
| Run a script while automatically installing deps | uv run --with <package> python script.py |
| Run a command inside the virtual environment | uv run -- <command> |
| Run a one-time CLI tool without installing globally | uvx <tool-name> --version |
| Install a tool globally | uv tool install <tool-name> |
| Upgrade a specific tool | uv tool upgrade <tool-name> |
| Upgrade all installed tools | uv tool upgrade --all |
| Enable shell auto-completion for uv | eval "$(uv generate-shell-completion bash)" |