uv: Manage Python projects, scripts, and tools
uv manages Python interpreters, project dependencies, virtual environmentsAn isolated folder where Python installs packages for one project, keeping them separate from other projects and your system Python. Learn more → , scripts, and command-line tools. Built by Astral, it combines tasks that otherwise require several tools. The important choice within uv is which environment should contain the code being run.
For a guided first project, start with Create your first Python project. This page connects uv’s workflows; the uv reference provides a command lookup.
Choose which environment owns the command
| Task | Workflow | Where dependencies belong |
|---|---|---|
| Develop an application or library | uv add, uv sync, uv run |
Project metadata and its managed environment |
| Share a standalone script | Inline dependency metadata and uv run |
A separate environment for the script |
| Run an independent command-line tool | uvx or uv tool install |
A tool environment separate from the project |
| Keep a requirements-file workflow | uv venv and uv pip |
An explicitly selected virtual environment |
Use project dependencies for tools that need to import the project’s code, such as its test runner. A separate tool environment is useful for a formatter that only needs to read source files. When to use uv run versus uvx explains that boundary.
Install uv
Follow How to install uv for macOS, Linux, or Windows. uv’s standalone installer does not require an existing Python installation.
Check that the command is available:
uv --versionThe output starts with uv, followed by the installed version. If the shell cannot find the command, reopen the terminal and check the installer’s PATH instructions. How to upgrade uv covers updates for each installation method.
Create and run a project
From a directory where a new tooling-demo folder can be created, run:
uv init --python 3.13 tooling-demo
cd tooling-demo
uv add requests
uv run tooling-demouv reports the initialized project and installs Requests and its dependencies. The generated application then prints:
Hello from tooling-demo!
uv run executes the command inside the project’s virtual environment, ensuring all dependencies are installed first. Shell activation is optional when commands run through uv.
The project separates declared requirements from installed files:
| File or directory | Purpose |
|---|---|
| pyproject.toml | Project metadata, declared dependencies, and tool configuration |
| uv.lockA file that records resolved dependency versions for repeatable installations. Supported Python versions and platforms may select different packages or builds. | Resolved dependency versions and artifacts for supported environments |
.python-version |
The requested interpreter version |
.venv/ |
The local environment created when dependencies are installed |
Commit the metadata, lockfile, Python version file, and source code. Recreate .venv from those files instead of committing it. A cross-platform lockfile may select different packages or wheel files on different operating systems; it does not make the resulting environments identical.
The default project includes a src/ package and a console command. uv init --lib creates a library layout; --no-package keeps the project layout flat (a main.py at the top level instead of a src/ package). Choose a uv project layout covers these options and minimal projects.
Keep installation tied to the lockfile
Inside tooling-demo, run:
uv sync --lockeduv checks that uv.lock agrees with the project’s requirements and synchronizes the environment. After the preceding example, no dependency changes are needed. If the requirements have changed without updating the lockfile, --locked fails instead of silently rewriting it.
Ordinary uv sync and uv run update the lockfile when the project requires it. They prefer compatible versions already locked; they do not upgrade every dependency just because a newer release exists. Lock and update dependencies covers deliberate upgrades and deployment workflows.
Run development tools in the project
Add Ruff to the example project and run its linter and formatter check:
uv add --dev ruff
uv run ruff check .
uv run ruff format --check .uv records Ruff in the dev dependency group and installs it. The generated project passes the lint check, and the formatter reports that its Python files are already formatted.
The --dev flag marks Ruff as a development dependencyA package needed during development (testing, linting, formatting) that is not shipped to users of your project. Installed with the --dev flag.
, keeping it out of production installs. Omit the development group during deployment with uv sync --locked --no-dev; ordinary uv sync includes it.
Use the same project-environment approach for running tests with pytest. Dependency groups and extras explains which dependencies belong in development groups and which are shipped to package users.
Select a compatible Python interpreter
requires-python in pyproject.toml declares the interpreter versions the project supports. .python-version requests an interpreter to use locally. A pin must fit the supported range; changing the pin alone does not change that range.
For the example project, which supports Python 3.13, run:
uv python pin 3.13
uv run python --versionuv writes 3.13 to .python-version, and Python reports a 3.13.x version. A minor-version pin permits different patch releases; use a full patch version when that distinction matters to the project.
uv can download supported prebuilt interpreters when needed or use a compatible interpreter already installed. Managed interpreters are stored separately from the package cache and shared between projects. See Install Python with uv and Change a project’s Python version for installation locations and compatibility checks.
Declare a standalone script’s dependencies
Save this complete file as report.py in a scratch directory:
# /// script
# dependencies = ["rich"]
# requires-python = ">=3.13"
# ///
from rich.console import Console
Console().print("Report ready")The inline script metadata format declares the script’s dependencies without a project directory. Run it from the directory containing report.py:
uv run report.pyAfter any installation messages, the script prints Report ready. uv installs Rich into a script-specific cached environment. For scripts with inline metadata, that environment is separate from an enclosing project’s dependencies.
Dependency names alone do not fix their versions for future runs. Write a self-contained script covers script dependencies; lock a script’s dependencies when the resolution needs to stay fixed.
Run tools separately from project dependencies
For a tool that does not need the project’s dependencies, uvx downloads and runs it in a separate environment. For example:
uvx ruff --versionThe output starts with ruff and its version. That version can differ from the Ruff locked in tooling-demo, so use uv run ruff for the project’s selected version.
uv tool install creates a persistent tool environment and places its executable in uv’s tool executable directory. That directory must be on PATH to run the command by name. Compare uv tools with pipx for installation and upgrades, or follow uv’s tool documentation for PATH setup.
Keep requirements files when the workflow needs them
The project commands maintain pyproject.toml and uv.lock. The uv pip commands instead install into an environment or compile requirements files without maintaining that project state. They also work for an existing requirements-file workflow.
In a separate scratch directory, create a virtual environment and install Requests:
uv venv
uv pip install --python .venv requestsuv reports the .venv it creates, then lists Requests and the dependencies it installs. --python .venv explicitly targets that environment even if another environment is active. Unlike uv add, this does not create a project dependency declaration or uv.lock.
A reproducible requirements workflow needs a resolved requirements file and a way to keep the environment synchronized with it.
Familiar commands do not imply identical behavior to pip. uv does not read pip-specific configuration such as pip.conf or PIP_INDEX_URL; index configuration and resolution rules need review when switching. Follow Translate pip commands to uv or Migrate requirements.txt to a uv project for the appropriate migration.
Assess speed on the workload that matters
Astral’s benchmark suite separates dependency resolution from installation and distinguishes cold from warm caches. Its results describe those workloads, not a guaranteed multiplier for every project. Source builds, network transfers, and filesystem behavior can dominate the time saved by changing installers.
For a useful comparison, hold Python and package versions constant, use fresh target environments, and state whether each tool’s cache is empty or populated. Measure the whole operation your team waits for. Timing an already satisfied environment against a fresh install answers a different question.
Check what changes when adopting uv
Standard project metadata and wheels support interoperability. Tool-specific source settings, plugins, and lockfiles need separate migration work. Which Python package manager should I use? covers when to adopt uv and when to keep another tool.
The default project’s configured build backend lets uv produce installable distributions. From tooling-demo, run:
uv buildThe build reports a source archive and wheel under dist/. Publishing is a separate step requiring a destination and credentials; follow Publish a Python package for that workflow. For an existing project, review its build backend and which files the distribution includes before publishing.
uv installs Python distributions, including compatible wheels containing compiled extensions. It does not resolve arbitrary system libraries as separate packages. A project needing that broader environment management may suit Pixi; see When to choose Pixi over uv.
Pick the next workflow to configure
- Editor: Configure VS Code for a uv project so it uses the project’s interpreter.
- CI: Set up GitHub Actions with uv and install from the committed lockfile.
- Containers: Build a production Docker image with dependencies and application code installed deliberately.
- Private indexes: Configure private package sources instead of relying on inherited pip settings.
- Dependency errors: Resolve Python version incompatibilities or check a missing project table.