Cheatsheet: uv
A handy reference for using UV, a better way to manage Python dependencies
About
| URL | https://github.com/astral-sh/uv |
| About | a better way to manage python dependencies |
Commands
| Init new project (in current dir) | uv init |
| Create venv for Python 3.12 | uv venv --python 3.12 |
| Pin project to Python 3.12 | uv python pin 3.12 |
| Install Python 3.12 | uv python install 3.12 |
| List Python versions installed/available | uv python list |
| List installed pkgs | uv pip list |
| Run with specific Python | uv run --python 3.12 script.py |
| Add runtime dependency | uv add httpx |
| Remove dependency | uv remove httpx |
Import from requirements.txt | uv add -r requirements.txt |
| Create/update lockfile | uv lock |
| Upgrade all locked deps | uv lock --upgrade |
| Sync env to lockfile (exact) | uv sync |
| Install from reqs file | uv pip install -r requirements.txt |
| Freeze installed pkgs | uv pip freeze > requirements.txt |
| Show project dependency tree | uv tree |
| Build sdist+wheel | uv build |
| Publish distributions | uv publish |
| Show cache directory | uv cache dir |
| Clean cache (all or named) | uv cache clean [PACKAGE...] |
| Prune unreachable cache objects | uv cache prune |
Subscribe to my monthly newsletter
No spam, no sharing to third party. Only you and me.