2024-02-15 11:19:46 -06:00
# uv
2023-10-05 12:44:36 -04:00
2024-02-15 11:19:46 -06:00
[](https://github.com/astral-sh/uv)
2024-02-16 19:45:29 -05:00
[](https://pypi.python.org/pypi/uv)
[](https://pypi.python.org/pypi/uv)
[](https://pypi.python.org/pypi/uv)
2024-02-15 11:19:46 -06:00
[](https://github.com/astral-sh/uv/actions)
2024-02-12 14:29:22 -05:00
[](https://discord.gg/astral-sh)
2024-02-04 13:56:00 -08:00
2024-02-15 09:54:29 -05:00
An extremely fast Python package installer and resolver, written in Rust. Designed as a drop-in
replacement for `pip` and `pip-compile` .
2023-10-07 19:39:56 -04:00
2024-02-15 11:19:46 -06:00
uv is backed by [Astral ](https://astral.sh ), the creators of [Ruff ](https://github.com/astral-sh/ruff ).
2023-10-07 19:39:56 -04:00
2024-01-03 22:22:01 -04:00
## Highlights
2023-10-07 19:39:56 -04:00
2024-02-12 18:45:26 -06:00
- ⚖️ Drop-in replacement for common `pip` , `pip-tools` , and `virtualenv` commands.
2024-02-15 11:19:46 -06:00
- ⚡️ [10-100x faster ](https://github.com/astral-sh/uv/blob/main/BENCHMARKS.md ) than `pip`
2024-02-15 09:54:29 -05:00
and `pip-tools` (`pip-compile` and `pip-sync` ).
2024-02-12 18:45:26 -06:00
- 💾 Disk-space efficient, with a global cache for dependency deduplication.
2024-02-15 11:19:46 -06:00
- 🐍 Installable via `curl` , `pip` , `pipx` , etc. uv is a static binary that can be installed
2024-02-15 09:54:29 -05:00
without Rust or Python.
2024-01-03 22:22:01 -04:00
- 🧪 Tested at-scale against the top 10,000 PyPI packages.
2024-01-30 13:39:15 -08:00
- 🖥️ Support for macOS, Linux, and Windows.
2024-02-15 16:09:27 -06:00
- 🧰 Advanced features such as [dependency version overrides ](#dependency-overrides ) and
2024-02-12 14:04:50 -06:00
[alternative resolution strategies ](#resolution-strategy ).
2024-02-08 17:12:22 -06:00
- ⁉️ Best-in-class error messages with a conflict-tracking resolver.
2024-02-15 23:22:44 -06:00
- 🤝 Support for a wide range of advanced `pip` features, including editable installs, Git
2024-02-12 18:45:26 -06:00
dependencies, direct URL dependencies, local dependencies, constraints, source distributions,
HTML and JSON indexes, and more.
2023-10-07 19:39:56 -04:00
2024-01-03 22:22:01 -04:00
## Getting Started
2023-10-07 19:39:56 -04:00
2024-02-15 11:19:46 -06:00
Install uv with our standalone installers, or from [PyPI ](https://pypi.org/project/uv/ ):
2023-10-07 19:39:56 -04:00
2024-01-03 22:22:01 -04:00
``` shell
2024-02-15 09:54:29 -05:00
# On macOS and Linux.
2024-02-15 11:19:46 -06:00
curl -LsSf https://astral.sh/uv/install.sh | sh
2024-02-15 09:54:29 -05:00
2024-02-22 10:25:33 +01:00
# On Windows.
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
2024-02-15 09:54:29 -05:00
# With pip.
2024-02-15 11:19:46 -06:00
pip install uv
2024-02-15 09:54:29 -05:00
# With pipx.
2024-02-15 11:19:46 -06:00
pipx install uv
2024-02-18 01:49:50 -06:00
# With Homebrew.
brew install uv
2024-02-20 17:33:56 +01:00
# With Pacman.
pacman -S uv
2024-01-03 22:22:01 -04:00
```
2024-02-15 09:54:29 -05:00
To create a virtual environment:
2024-01-03 22:22:01 -04:00
``` shell
2024-02-15 11:19:46 -06:00
uv venv # Create a virtual environment at .venv.
2024-01-03 22:22:01 -04:00
```
2023-10-09 11:48:39 -04:00
2024-02-15 21:20:25 -05:00
To activate the virtual environment:
``` shell
# On macOS and Linux.
source .venv/bin/activate
# On Windows.
2024-02-21 17:16:40 -05:00
.venv\S cripts\a ctivate
2024-02-15 21:20:25 -05:00
```
2024-01-03 22:22:01 -04:00
To install a package into the virtual environment:
``` shell
2024-02-15 11:19:46 -06:00
uv pip install flask # Install Flask.
uv pip install -r requirements.txt # Install from a requirements.txt file.
uv pip install -e . # Install the current project in editable mode.
2024-02-16 09:34:04 -05:00
uv pip install "package @ ." # Install the current project from disk
2024-02-21 21:13:07 -05:00
uv pip install "flask[dotenv]" # Install Flask with "dotenv" extra.
2024-01-03 22:22:01 -04:00
```
To generate a set of locked dependencies from an input file:
``` shell
2024-02-15 11:19:46 -06:00
uv pip compile pyproject.toml -o requirements.txt # Read a pyproject.toml file.
uv pip compile requirements.in -o requirements.txt # Read a requirements.in file.
2024-01-03 22:22:01 -04:00
```
2024-02-15 09:54:29 -05:00
To sync a set of locked dependencies with the virtual environment:
2024-01-03 22:22:01 -04:00
``` shell
2024-02-15 11:19:46 -06:00
uv pip sync requirements.txt # Install from a requirements.txt file.
2024-01-03 22:22:01 -04:00
```
2024-02-15 15:22:29 -06:00
uv's `pip-install` and `pip-compile` commands support many of the same command-line arguments
2024-01-03 22:22:01 -04:00
as existing tools, including `-r requirements.txt` , `-c constraints.txt` , `-e .` (for editable
installs), `--index-url` , and more.
2023-10-07 19:39:56 -04:00
## Limitations
2024-02-15 11:19:46 -06:00
uv does not support the entire `pip` feature set. Namely, uv does not (and does not plan to)
2024-02-15 09:54:29 -05:00
support the following `pip` features:
2024-01-03 22:22:01 -04:00
- `.egg` dependencies
2024-01-30 13:39:15 -08:00
- Editable installs for Git and direct URL dependencies (editable installs _ are _ supported for local
dependencies)
2023-10-07 19:39:56 -04:00
2024-02-15 11:19:46 -06:00
On the other hand, uv plans to (but does not currently) support:
2024-01-03 22:22:01 -04:00
2024-02-15 11:19:46 -06:00
- [Hash-checking mode ](https://github.com/astral-sh/uv/issues/474 )
- [URL requirements without package names ](https://github.com/astral-sh/uv/issues/313 )
2024-02-15 12:01:54 -05:00
(e.g., `https://...` instead of `package @ https://...` )
2023-10-07 19:39:56 -04:00
2024-02-15 11:19:46 -06:00
Like `pip-compile` , uv generates a platform-specific `requirements.txt` file (unlike, e.g.,
2024-01-03 22:22:01 -04:00
`poetry` and `pdm` , which generate platform-agnostic `poetry.lock` and `pdm.lock` files). As such,
2024-02-15 11:19:46 -06:00
uv's `requirements.txt` files may not be portable across platforms and Python versions.
2023-10-05 12:44:36 -04:00
2024-02-15 09:54:29 -05:00
## Roadmap
2024-02-15 11:19:46 -06:00
uv is an extremely fast Python package resolver and installer, designed as a drop-in
2024-02-15 09:54:29 -05:00
replacement for `pip` , `pip-tools` (`pip-compile` and `pip-sync` ), and `virtualenv` .
2024-02-15 11:19:46 -06:00
uv represents an intermediary goal in our pursuit of a ["Cargo for Python" ](https://blog.rust-lang.org/2016/05/05/cargo-pillars.html#pillars-of-cargo ):
2024-02-15 09:54:29 -05:00
a comprehensive project and package manager that is extremely fast, reliable, and easy to use.
Think: a single binary that bootstraps your Python installation and gives you everything you need to
be productive with Python, bundling not only `pip` , `pip-tools` , and `virtualenv` , but also `pipx` ,
`tox` , `poetry` , `pyenv` , `ruff` , and more.
2024-02-15 11:19:46 -06:00
Our goal is to evolve uv into such a tool.
2024-02-15 09:54:29 -05:00
In the meantime, though, the narrower `pip-tools` scope allows us to solve the low-level problems
involved in building such a tool (like package installation) while shipping something immediately
2024-02-15 23:22:44 -06:00
useful with a minimal barrier to adoption.
2024-02-15 09:54:29 -05:00
2024-01-03 22:22:01 -04:00
## Advanced Usage
2023-10-05 12:44:36 -04:00
2024-01-05 09:44:06 -05:00
### Python discovery
2024-02-15 11:19:46 -06:00
uv itself does not depend on Python, but it does need to locate a Python environment to (1)
2024-01-31 07:42:32 -08:00
install dependencies into the environment and (2) build source distributions.
2024-01-05 09:44:06 -05:00
2024-02-15 11:19:46 -06:00
When running `pip sync` or `pip install` , uv will search for a virtual environment in the
2024-01-05 09:44:06 -05:00
following order:
- An activated virtual environment based on the `VIRTUAL_ENV` environment variable.
- An activated Conda environment based on the `CONDA_PREFIX` environment variable.
- A virtual environment at `.venv` in the current directory, or in the nearest parent directory.
2024-02-15 11:19:46 -06:00
If no virtual environment is found, uv will prompt the user to create one in the current
directory via `uv venv` .
2024-01-05 16:01:06 +01:00
2024-02-15 11:19:46 -06:00
When running `pip compile` , uv does not _ require _ a virtual environment and will search for a
2024-01-05 16:01:06 +01:00
Python interpreter in the following order:
- An activated virtual environment based on the `VIRTUAL_ENV` environment variable.
- An activated Conda environment based on the `CONDA_PREFIX` environment variable.
- A virtual environment at `.venv` in the current directory, or in the nearest parent directory.
2024-01-31 07:42:32 -08:00
- The Python interpreter available as `python3` on macOS and Linux, or `python.exe` on Windows.
2024-02-15 11:19:46 -06:00
If a `--python-version` is provided to `pip compile` (e.g., `--python-version=3.7` ), uv will
2024-01-31 07:42:32 -08:00
search for a Python interpreter matching that version in the following order:
- An activated virtual environment based on the `VIRTUAL_ENV` environment variable.
- An activated Conda environment based on the `CONDA_PREFIX` environment variable.
- A virtual environment at `.venv` in the current directory, or in the nearest parent directory.
2024-02-15 11:19:46 -06:00
- The Python interpreter available as, e.g., `python3.7` on macOS and Linux. On Windows, uv
2024-01-31 07:42:32 -08:00
will use the same mechanism as `py --list-paths` to discover all available Python interpreters,
and will select the first interpreter matching the requested version.
- The Python interpreter available as `python3` on macOS and Linux, or `python.exe` on Windows.
2024-02-15 11:19:46 -06:00
Since uv has no dependency on Python, it can even install into virtual environments other than
its own. For example, setting `VIRTUAL_ENV=/path/to/venv` will cause uv to install into
`/path/to/venv` , no matter where uv is installed.
2024-01-05 09:44:06 -05:00
2024-02-27 21:54:33 -05:00
Finally, uv can also install into non-virtual environments by providing a `--python` argument to
`pip sync` or `pip install` . For example, `uv pip install --python=/path/to/python` will install
into the environment linked to the `/path/to/python` interpreter. Though we generally recommend the
use of virtual environments for dependency management, this feature can be useful for installing
into system Python installations in continuous integration or containerized environments.
2024-02-21 20:30:11 -06:00
### Git authentication
uv allows packages to be installed from Git and supports the following schemes for authenticating with private
repositories.
Using SSH:
- `git+ssh://git@<hostname>/...` (e.g. `git+ssh://git@github.com/astral-sh/uv` )
- `git+ssh://git@<host>/...` (e.g. `git+ssh://git@github.com-key-2/astral-sh/uv` )
See the [GitHub SSH documentation ](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh ) for more details on how to configure SSH.
Using a password or token:
- `git+https://<user>:<token>@<hostname>/...` (e.g. `git+https://git:github_pat_asdf@github.com/astral-sh/uv` )
- `git+https://<token>@<hostname>/...` (e.g. `git+https://github_pat_asdf@github.com/astral-sh/uv` )
- `git+https://<user>@<hostname>/...` (e.g. `git+https://git@github.com/astral-sh/uv` )
When using a GitHub personal access token, the username is arbitrary. GitHub does not support logging in with password directly, although other hosts may. If a username is provided without credentials, you will be prompted to enter them.
If there are no credentials present in the URL and authentication is needed, the [Git credential helper ](https://git-scm.com/doc/credential-helpers ) will be queried.
2024-01-04 01:36:33 -04:00
### Dependency caching
2024-02-15 11:19:46 -06:00
uv uses aggressive caching to avoid re-downloading (and re-building dependencies) that have
2024-01-04 01:36:33 -04:00
already been accessed in prior runs.
2024-02-16 19:45:29 -05:00
The specifics of uv's caching semantics vary based on the nature of the dependency:
2024-01-04 01:36:33 -04:00
2024-02-15 11:19:46 -06:00
- **For registry dependencies** (like those downloaded from PyPI), uv respects HTTP caching headers.
- **For direct URL dependencies**, uv respects HTTP caching headers, and also caches based on
2024-01-04 01:36:33 -04:00
the URL itself.
2024-02-15 11:19:46 -06:00
- **For Git dependencies**, uv caches based on the fully-resolved Git commit hash. As such,
`uv pip compile` will pin Git dependencies to a specific commit hash when writing the resolved
2024-01-04 01:36:33 -04:00
dependency set.
2024-02-15 11:19:46 -06:00
- **For local dependencies**, uv caches based on the last-modified time of the `setup.py` or
2024-01-04 01:36:33 -04:00
`pyproject.toml` file.
2024-02-15 11:19:46 -06:00
If you're running into caching issues, uv includes a few escape hatches:
2024-01-04 01:36:33 -04:00
2024-02-15 11:19:46 -06:00
- To force uv to revalidate cached data for all dependencies, run `uv pip install --refresh ...` .
- To force uv to revalidate cached data for a specific dependency, run, e.g., `uv pip install --refresh-package flask ...` .
- To force uv to ignore existing installed versions, run `uv pip install --reinstall ...` .
2024-02-19 23:14:05 -05:00
- To clear the global cache entirely, run `uv cache clean` .
2024-01-04 01:36:33 -04:00
2024-01-03 22:22:01 -04:00
### Resolution strategy
2023-10-06 01:02:14 -04:00
2024-02-15 11:19:46 -06:00
By default, uv follows the standard Python dependency resolution strategy of preferring the
latest compatible version of each package. For example, `uv pip install flask>=2.0.0` will
2024-01-04 01:36:33 -04:00
install the latest version of Flask (at time of writing: `3.0.0` ).
2024-01-03 22:22:01 -04:00
2024-02-24 17:15:01 -05:00
However, uv's resolution strategy can be configured to support alternative workflows. With
`--resolution=lowest` , uv will install the **lowest ** compatible versions for all dependencies,
both **direct ** and **transitive ** . Alternatively, `--resolution=lowest-direct` will opt for the
**lowest ** compatible versions for all **direct ** dependencies, while using the **latest **
compatible versions for all **transitive ** dependencies. This distinction can be particularly useful
for library authors who wish to test against the lowest supported versions of direct dependencies
without restricting the versions of transitive dependencies.
2024-01-03 22:22:01 -04:00
For example, given the following `requirements.in` file:
``` text
flask>=2.0.0
2023-10-06 01:02:14 -04:00
```
2024-02-15 11:19:46 -06:00
Running `uv pip compile requirements.in` would produce the following `requirements.txt` file:
2023-10-06 01:02:14 -04:00
2024-01-03 22:22:01 -04:00
``` text
2024-02-19 15:26:53 -05:00
# This file was autogenerated by uv via the following command:
2024-02-15 11:19:46 -06:00
# uv pip compile requirements.in
2024-01-03 22:22:01 -04:00
blinker==1.7.0
# via flask
click==8.1.7
# via flask
flask==3.0.0
itsdangerous==2.1.2
# via flask
jinja2==3.1.2
# via flask
markupsafe==2.1.3
# via
# jinja2
# werkzeug
werkzeug==3.0.1
# via flask
2023-10-05 12:44:36 -04:00
```
2024-02-15 11:19:46 -06:00
However, `uv pip compile --resolution=lowest requirements.in` would instead produce:
2023-10-07 19:39:56 -04:00
``` text
2024-02-19 15:26:53 -05:00
# This file was autogenerated by uv via the following command:
2024-02-15 11:19:46 -06:00
# uv pip compile requirements.in --resolution=lowest
2024-01-03 22:22:01 -04:00
click==7.1.2
# via flask
flask==2.0.0
itsdangerous==2.0.0
# via flask
jinja2==3.0.0
# via flask
markupsafe==2.0.0
# via jinja2
werkzeug==2.0.0
# via flask
2023-10-07 19:39:56 -04:00
```
2024-01-03 22:22:01 -04:00
### Pre-release handling
2024-02-15 11:19:46 -06:00
By default, uv will accept pre-release versions during dependency resolution in two cases:
2024-01-03 22:22:01 -04:00
1. If the package is a direct dependency, and its version markers include a pre-release specifier
(e.g., `flask>=2.0.0rc1` ).
1. If _ all _ published versions of a package are pre-releases.
2024-02-15 11:19:46 -06:00
If dependency resolution fails due to a transitive pre-release, uv will prompt the user to
2024-01-04 01:36:33 -04:00
re-run with `--prerelease=allow` , to allow pre-releases for all dependencies.
2024-02-16 19:45:29 -05:00
Alternatively, you can add the transitive dependency to your `requirements.in` file with
2024-01-04 01:36:33 -04:00
pre-release specifier (e.g., `flask>=2.0.0rc1` ) to opt in to pre-release support for that specific
dependency.
2024-01-03 22:22:01 -04:00
2024-01-04 01:36:33 -04:00
Pre-releases are [notoriously difficult ](https://pubgrub-rs-guide.netlify.app/limitations/prerelease_versions )
2024-02-15 11:19:46 -06:00
to model, and are a frequent source of bugs in other packaging tools. uv's pre-release handling
2024-01-04 01:36:33 -04:00
is _ intentionally _ limited and _ intentionally _ requires user intervention to opt in to pre-releases
to ensure correctness, though pre-release handling will be revisited in future releases.
2024-01-03 22:22:01 -04:00
### Dependency overrides
Historically, `pip` has supported "constraints" (`-c constraints.txt` ), which allows users to
narrow the set of acceptable versions for a given package.
2024-02-15 11:19:46 -06:00
uv supports constraints, but also takes this concept further by allowing users to _ override _ the
2024-02-19 00:55:27 +01:00
acceptable versions of a package across the dependency tree via overrides (`--override overrides.txt` ).
2024-01-03 22:22:01 -04:00
In short, overrides allow the user to lie to the resolver by overriding the declared dependencies
of a package. Overrides are a useful last resort for cases in which the user knows that a
dependency is compatible with a newer version of a package than the package declares, but the
package has not yet been updated to declare that compatibility.
For example, if a transitive dependency declares `pydantic>=1.0,<2.0` , but the user knows that
the package is compatible with `pydantic>=2.0` , the user can override the declared dependency
with `pydantic>=2.0,<3` to allow the resolver to continue.
While constraints are purely _ additive _ , and thus cannot _ expand _ the set of acceptable versions for
a package, overrides _ can _ expand the set of acceptable versions for a package, providing an escape
hatch for erroneous upper version bounds.
### Multi-version resolution
2024-02-15 11:19:46 -06:00
uv's `pip-compile` command produces a resolution that's known to be compatible with the
current platform and Python version. Unlike Poetry, PDM, and other package managers, uv does
2024-01-03 22:22:01 -04:00
not yet produce a machine-agnostic lockfile.
2024-02-15 11:19:46 -06:00
However, uv _ does _ support resolving for alternate Python versions via the `--python-version`
command line argument. For example, if you're running uv on Python 3.9, but want to resolve for
Python 3.8, you can run `uv pip compile --python-version=3.8 requirements.in` to produce a
2024-01-03 22:22:01 -04:00
Python 3.8-compatible resolution.
2024-01-28 19:52:25 -08:00
## Platform support
2024-02-15 11:19:46 -06:00
uv has Tier 1 support for the following platforms:
2024-01-28 19:52:25 -08:00
- macOS (Apple Silicon)
- macOS (x86_64)
- Linux (x86_64)
- Windows (x86_64)
2024-02-15 11:19:46 -06:00
uv is continuously built, tested, and developed against its Tier 1 platforms. Inspired by the
2024-01-28 19:52:25 -08:00
Rust project, Tier 1 can be thought of as ["guaranteed to work" ](https://doc.rust-lang.org/beta/rustc/platform-support.html ).
2024-02-15 11:19:46 -06:00
uv has Tier 2 support (["guaranteed to build" ](https://doc.rust-lang.org/beta/rustc/platform-support.html )) for the following platforms:
2024-01-28 19:52:25 -08:00
- Linux (PPC64)
- Linux (PPC64LE)
- Linux (aarch64)
2024-01-29 05:50:23 -08:00
- Linux (armv7)
2024-01-28 19:52:25 -08:00
- Linux (i686)
- Linux (s390x)
2024-02-15 11:19:46 -06:00
uv ships pre-built wheels to [PyPI ](https://pypi.org/project/uv/ ) for its Tier 1 and
2024-01-28 19:52:25 -08:00
Tier 2 platforms. However, while Tier 2 platforms are continuously built, they are not continuously
tested or developed against, and so stability may vary in practice.
2024-02-15 11:19:46 -06:00
Beyond the Tier 1 and Tier 2 platforms, uv is known to build on i686 Windows, and known _ not _
2024-01-28 19:52:25 -08:00
to build on aarch64 Windows, but does not consider either platform to be supported at this time.
2024-02-15 11:19:46 -06:00
uv supports and is tested against Python 3.8, 3.9, 3.10, 3.11, and 3.12.
2024-02-04 13:56:00 -08:00
2024-01-03 22:22:01 -04:00
## Acknowledgements
2024-02-15 11:19:46 -06:00
uv's dependency resolver uses [PubGrub ](https://github.com/pubgrub-rs/pubgrub ) under the hood.
2024-01-03 22:22:01 -04:00
We're grateful to the PubGrub maintainers, especially [Jacob Finkelman ](https://github.com/Eh2406 ),
for their support.
2024-02-15 11:19:46 -06:00
uv's Git implementation is based on [Cargo ](https://github.com/rust-lang/cargo ).
2024-01-03 22:22:01 -04:00
2024-02-15 11:19:46 -06:00
Some of uv's optimizations are inspired by the great work we've seen in
2024-02-15 12:01:54 -05:00
[pnpm ](https://pnpm.io/ ), [Orogene ](https://github.com/orogene/orogene ), and
[Bun ](https://github.com/oven-sh/bun ). We've also learned a lot from Nathaniel
J. Smith's [Posy ](https://github.com/njsmith/posy ) and adapted its [trampoline ](https://github.com/njsmith/posy/tree/main/src/trampolines/windows-trampolines/posy-trampoline )
for Windows support.
2024-01-03 22:22:01 -04:00
2023-10-05 12:44:36 -04:00
## License
2024-02-15 11:19:46 -06:00
uv is licensed under either of
2023-10-05 12:44:36 -04:00
- Apache License, Version 2.0, ([LICENSE-APACHE ](LICENSE-APACHE ) or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT ](LICENSE-MIT ) or https://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
2024-02-15 11:19:46 -06:00
for inclusion in uv by you, as defined in the Apache-2.0 license, shall be
2023-10-05 12:44:36 -04:00
dually licensed as above, without any additional terms or conditions.
<div align="center">
<a target="_blank" href="https://astral.sh" style="background:none">
2024-02-15 23:22:44 -06:00
<img src="https://raw.githubusercontent.com/astral-sh/uv/main/assets/svg/Astral.svg" alt="Made by Astral">
2023-10-05 12:44:36 -04:00
</a>
</div>