uv Fast Python package manager

Version 0.13.0 · source

Start here

uv init <name>
New project
uv add <pkg>
Add a dependency
uv run <cmd>
Run in the project env
uv sync
Install from the lockfile
uv lock --upgrade
Refresh all locked versions
uvx <tool>
Run a tool, no install
uv python install <ver>
Get a Python
uv pip install <pkg>
pip-style install

Concepts

  1. pyproject.toml your dependencies
  2. uv.lock exact pinned versions
  3. .venv installed packages
  4. Your command runs inside .venv
Project workflow

Projects

uv init <name>
Create a project in a new directory
uv init
Initialise the current directory
uv init --lib <name>
Library layout with src/ and build system
uv init --app <name>
Application project
uv add <pkg>...
Add dependencies and install them
uv add '<pkg>>=<ver>'
Add with a version constraint
uv add --dev <pkg>
Add to the dev dependency group
uv add --group <name> <pkg>
Add to a named dependency group
uv add <pkg> --optional <extra>
Add to an optional extra
uv add -r requirements.txt
Import dependencies from a requirements file
uv add --editable <path>
Add a local package in editable mode
uv remove <pkg>...
Remove dependencies
uv sync
Make .venv match the lockfile exactly
uv sync --locked
Fail if uv.lock is out of date (CI)
uv sync --frozen
Install from uv.lock without re-locking
uv sync --no-dev
Skip the dev group
uv sync --all-extras
Include every optional extra
uv sync --all-groups
Include every dependency group
uv lock
Write or update uv.lock
uv lock --upgrade
Re-resolve to the newest allowed versions
uv lock --upgrade-package <pkg>
Upgrade one package only
uv lock --check
Verify the lockfile is current
uv tree
Show the dependency tree
uv tree --outdated
Mark packages with newer versions
uv version
Show the project version
uv version --bump <part>
Bump major, minor or patch
uv export -o requirements.txt
Export the lock as a requirements file
uv build
Build sdist and wheel into dist/
uv publish
Upload dist/ files to PyPI

Running

uv run <cmd> [args]
Run a command in the project environment
uv run python
Python REPL with project deps
uv run <script.py>
Run a script (inline metadata is honoured)
uv run --with <pkg> <cmd>
Add a temporary dependency for this run
uv run --no-project <script.py>
Ignore the surrounding project
uv run --python <ver> <cmd>
Run on a specific Python version
uv run --no-sync <cmd>
Skip the auto-sync step
uv run --locked <cmd>
Error if the lockfile needs changes
uv run --group <name> <cmd>
Include a dependency group
uv init --script <file.py>
Create a script with inline metadata
uv add --script <file.py> <pkg>
Declare a script's dependencies
uv lock --script <file.py>
Lock a script's dependencies

Tools

uvx <tool> [args]
Run a tool in a throwaway env
Alias for uv tool run.
uvx <tool>@<ver> [args]
Run an exact version
uvx <tool>@latest [args]
Run the newest version
uvx --from <pkg> <cmd>
Command name differs from package name
uvx --with <pkg> <tool>
Add extra packages to the tool env
uv tool install <pkg>
Install a tool onto PATH
uv tool install '<pkg>>=<ver>'
Install with a version constraint
uv tool list
List installed tools
uv tool upgrade <pkg>
Upgrade within its original constraint
uv tool upgrade --all
Upgrade every installed tool
uv tool uninstall <pkg>
Remove an installed tool
uv tool update-shell
Add the tool bin dir to your PATH
uv tool dir
Print the tools directory

Python versions

uv python install <ver>
Download a managed Python
uv python install <ver> <ver>
Install several versions
uv python list
Show available and installed Pythons
uv python find [<ver>]
Print the path of a matching interpreter
uv python pin <ver>
Write .python-version for this directory
uv python upgrade [<ver>]
Move to the latest patch release
uv python uninstall <ver>
Remove a managed Python
uv python dir
Print where Pythons are stored

Virtual envs and pip

uv venv [<path>]
Create a venv (default .venv)
uv venv --python <ver>
Create with a specific Python
uv pip install <pkg>
Install into the active or local .venv
uv pip install -r requirements.txt
Install from a requirements file
uv pip install -e .
Editable install of the current project
uv pip uninstall <pkg>
Uninstall a package
uv pip freeze
List installed packages pinned
uv pip list
List installed packages
uv pip show <pkg>
Show package details
uv pip tree
Show installed dependency tree
uv pip check
Check installed packages are compatible
uv pip compile <in> -o requirements.txt
Resolve to a pinned requirements file
uv pip compile <in> --upgrade-package <pkg>
Upgrade one pin while compiling
uv pip sync requirements.txt
Make the env exactly match the file
Unlike install, sync removes packages that are not listed.

Cache and self

uv cache dir
Print the cache location
uv cache prune
Drop unused cache entries
uv cache clean
Wipe the whole cache
uv self update
Update uv (standalone installs)
uv self version
Show uv's own version
uv --version
Print the uv version
uv help <command>
Show help for a command
uv generate-shell-completion <shell>
Print a shell completion script

Recipes

Start a new app with dev tools
uv init myapp && cd myappuv add requestsuv add --dev pytest ruffuv run pytest
Reproducible CI install
uv sync --locked --no-devuv run --no-sync python -m myapp
Single-file script with dependencies
uv init --script fetch.py --python 3.12uv add --script fetch.py requests richuv run fetch.py
Try a tool and pin a Python
# run once, nothing installeduvx ruff check .uv python pin 3.12uv venv && uv pip install -r requirements.txt