uv
CLI
tool
package manager
uv is a Python package manager with additional features for managing Python versions, scripts, projects, and tools.
Concepts
- Projects: You can manage packages project-wide using
uv
commands and theproject.toml
file. - Scripts: You can also manage packages for independent scripts using
uv
commands using the script-header in a python script. - Scripts: You can also manage packages for independent scripts using
uv
commands using the script-header in a python script. - Tools: To run packages as commandline tools, you can use special
uv
commands.
Installation
- Install uv
-
pipx install uv
- Upgrade uv
-
uv self update
Python Versions
Manage Python installations and versions.
- Install Python versions
-
uv python install 3.9.7
- List available Python versions
-
uv python list
- Find an installed Python version
-
uv python find 3.9
- Pin a project to a specific Python version
-
uv python pin 3.9.7
- Uninstall a Python version
-
uv python uninstall 3.9.7
Scripts
Execute and manage dependencies in standalone Python scripts. The script needs to contain a script header.
- script header
- ```python # /// script # dependencies = [ # “requests<3”, # “rich”, # ] # ///
import requests from rich import print …
Run a script
: ```bash
uv run example.py
- Add a dependency to a script
-
uv add --script SomePackage
- Remove a dependency from a script
-
uv remove --script SomePackage
Projects
Create and manage depencies of whole projects with a pyproject.toml
file.
- Create a new project with a
pyproject.toml
file and a virtual environment -
uv init
- Add a dependency to the project
-
uv add SomePackage
- Remove a dependency from the project
-
uv remove SomePackage
- Sync project dependencies with the virtual environment
-
uv sync
- Create a lockfile for dependencies
-
uv lock
- Run a command in the project environment
-
uv run python script.py
- View the dependency tree
-
uv tree
Tools
Install and manage tools from Python package indexes.
- Run a tool in a temporary environment
-
uvx ruff
- Install a tool user-wide
-
uv tool install black
- Uninstall a tool
-
uv tool uninstall black
- List installed tools
-
uv tool list
- Update the shell to include tool executables
-
uv tool update-shell