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.12uv venv --python 3.12
Pin project to Python 3.12uv python pin 3.12
Install Python 3.12uv python install 3.12
List Python versions installed/availableuv python list
List installed pkgsuv pip list
Run with specific Pythonuv run --python 3.12 script.py
Add runtime dependencyuv add httpx
Remove dependencyuv remove httpx
Import from requirements.txtuv add -r requirements.txt
Create/update lockfileuv lock
Upgrade all locked depsuv lock --upgrade
Sync env to lockfile (exact)uv sync
Install from reqs fileuv pip install -r requirements.txt
Freeze installed pkgsuv pip freeze > requirements.txt
Show project dependency treeuv tree
Build sdist+wheeluv build
Publish distributionsuv publish
Show cache directoryuv cache dir
Clean cache (all or named)uv cache clean [PACKAGE...]
Prune unreachable cache objectsuv cache prune
Subscribe to my monthly newsletter

No spam, no sharing to third party. Only you and me.