astral-sh / uv
- воскресенье, 18 февраля 2024 г. в 00:00:02
An extremely fast Python package installer and resolver, written in Rust.
An extremely fast Python package installer and resolver, written in Rust. Designed as a drop-in
replacement for pip
and pip-compile
.
uv is backed by Astral, the creators of Ruff.
pip
, pip-tools
, and virtualenv
commands.pip
and pip-tools
(pip-compile
and pip-sync
).curl
, pip
, pipx
, etc. uv is a static binary that can be installed
without Rust or Python.pip
features, including editable installs, Git
dependencies, direct URL dependencies, local dependencies, constraints, source distributions,
HTML and JSON indexes, and more.Install uv with our standalone installers, or from PyPI:
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows.
irm https://astral.sh/uv/install.ps1 | iex
# With pip.
pip install uv
# With pipx.
pipx install uv
To create a virtual environment:
uv venv # Create a virtual environment at .venv.
To activate the virtual environment:
# On macOS and Linux.
source .venv/bin/activate
# On Windows.
.\.venv\Scripts\activate.ps1
To install a package into the virtual environment:
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.
uv pip install "package @ ." # Install the current project from disk
To generate a set of locked dependencies from an input file:
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.
To sync a set of locked dependencies with the virtual environment:
uv pip sync requirements.txt # Install from a requirements.txt file.
uv's pip-install
and pip-compile
commands support many of the same command-line arguments
as existing tools, including -r requirements.txt
, -c constraints.txt
, -e .
(for editable
installs), --index-url
, and more.
uv does not support the entire pip
feature set. Namely, uv does not (and does not plan to)
support the following pip
features:
.egg
dependenciesOn the other hand, uv plans to (but does not currently) support:
https://...
instead of package @ https://...
)Like pip-compile
, uv generates a platform-specific requirements.txt
file (unlike, e.g.,
poetry
and pdm
, which generate platform-agnostic poetry.lock
and pdm.lock
files). As such,
uv's requirements.txt
files may not be portable across platforms and Python versions.
uv is an extremely fast Python package resolver and installer, designed as a drop-in
replacement for pip
, pip-tools
(pip-compile
and pip-sync
), and virtualenv
.
uv represents an intermediary goal in our pursuit of a "Cargo for Python": 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.
Our goal is to evolve uv into such a tool.
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
useful with a minimal barrier to adoption.
uv itself does not depend on Python, but it does need to locate a Python environment to (1) install dependencies into the environment and (2) build source distributions.
When running pip sync
or pip install
, uv will search for a virtual environment in the
following order:
VIRTUAL_ENV
environment variable.CONDA_PREFIX
environment variable..venv
in the current directory, or in the nearest parent directory.If no virtual environment is found, uv will prompt the user to create one in the current
directory via uv venv
.
When running pip compile
, uv does not require a virtual environment and will search for a
Python interpreter in the following order:
VIRTUAL_ENV
environment variable.CONDA_PREFIX
environment variable..venv
in the current directory, or in the nearest parent directory.python3
on macOS and Linux, or python.exe
on Windows.If a --python-version
is provided to pip compile
(e.g., --python-version=3.7
), uv will
search for a Python interpreter matching that version in the following order:
VIRTUAL_ENV
environment variable.CONDA_PREFIX
environment variable..venv
in the current directory, or in the nearest parent directory.python3.7
on macOS and Linux. On Windows, uv
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.python3
on macOS and Linux, or python.exe
on Windows.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.
uv uses aggressive caching to avoid re-downloading (and re-building dependencies) that have already been accessed in prior runs.
The specifics of uv's caching semantics vary based on the nature of the dependency:
uv pip compile
will pin Git dependencies to a specific commit hash when writing the resolved
dependency set.setup.py
or
pyproject.toml
file.If you're running into caching issues, uv includes a few escape hatches:
uv pip install --refresh ...
.uv pip install --refresh-package flask ...
.uv pip install --reinstall ...
.uv clean
.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
install the latest version of Flask (at time of writing: 3.0.0
).
However, uv's resolution strategy can be configured to prefer the lowest compatible version of
each package (--resolution=lowest
), or even the lowest compatible version of any direct
dependencies (--resolution=lowest-direct
), both of which can be useful for library authors looking
to test their packages against the oldest supported versions of their dependencies.
For example, given the following requirements.in
file:
flask>=2.0.0
Running uv pip compile requirements.in
would produce the following requirements.txt
file:
# This file was autogenerated by uv v0.0.1 via the following command:
# uv pip compile requirements.in
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
However, uv pip compile --resolution=lowest requirements.in
would instead produce:
# This file was autogenerated by uv v0.0.1 via the following command:
# uv pip compile requirements.in --resolution=lowest
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
By default, uv will accept pre-release versions during dependency resolution in two cases:
flask>=2.0.0rc1
).If dependency resolution fails due to a transitive pre-release, uv will prompt the user to
re-run with --prerelease=allow
, to allow pre-releases for all dependencies.
Alternatively, you can add the transitive dependency to your requirements.in
file with
pre-release specifier (e.g., flask>=2.0.0rc1
) to opt in to pre-release support for that specific
dependency.
Pre-releases are notoriously difficult to model, and are a frequent source of bugs in other packaging tools. uv's pre-release handling 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.
Historically, pip
has supported "constraints" (-c constraints.txt
), which allows users to
narrow the set of acceptable versions for a given package.
uv supports constraints, but also takes this concept further by allowing users to override the
acceptable versions of a package across the dependency tree via overrides (-o overrides.txt
).
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.
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
not yet produce a machine-agnostic lockfile.
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
Python 3.8-compatible resolution.
uv has Tier 1 support for the following platforms:
uv is continuously built, tested, and developed against its Tier 1 platforms. Inspired by the Rust project, Tier 1 can be thought of as "guaranteed to work".
uv has Tier 2 support ("guaranteed to build") for the following platforms:
uv ships pre-built wheels to PyPI for its Tier 1 and 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.
Beyond the Tier 1 and Tier 2 platforms, uv is known to build on i686 Windows, and known not to build on aarch64 Windows, but does not consider either platform to be supported at this time.
uv supports and is tested against Python 3.8, 3.9, 3.10, 3.11, and 3.12.
uv's dependency resolver uses PubGrub under the hood. We're grateful to the PubGrub maintainers, especially Jacob Finkelman, for their support.
uv's Git implementation is based on Cargo.
Some of uv's optimizations are inspired by the great work we've seen in pnpm, Orogene, and Bun. We've also learned a lot from Nathaniel J. Smith's Posy and adapted its trampoline for Windows support.
uv is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in uv by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.