Quick facts
- Similar to
poetry
API - Python compliant
- Uses
.python-version
likepyenv
- Uses
pyproject.toml
likepip
- Uses
.venv
as default
- Uses
pyproject.toml
governeduv venv
equivalent topython -m venv .venv
uv pip ...
equivalent topip ...
- Easy and quick installation
curl -LsSf https://astral.sh/uv/install.sh | sh
- Upgrade with
uv self update
Note: Screenshot comparing
poetry
(top) anduv
(down). You can see the different implementations of thepyproject.toml
and the performance (15s vs 1s).
Development
Common tasks we will find and use:
- Minimal scaffolding
- Manage venv/dependencies
- Manage Python versions
- Build distributions
Example
|
|
Resources:
- https://docs.astral.sh/uv/getting-started/features/
- https://docs.astral.sh/uv/guides/projects/
- https://docs.astral.sh/uv/concepts/python-versions/#adjusting-python-version-preferences
- https://docs.astral.sh/uv/guides/integration/docker/
They Move Fast and Stick to the Standard
They have an amazing philosophy of using built-in Python tools. An example of
this, previously, they used the [tool.uv]
table inside the pyproject.toml
like this:
|
|
to handle dev dependencies, now (uv 0.5.4 (c62c83c37 2024-11-20)
) they
replaced that in favor of dependency groups, becoming something like this:
|
|
[!NOTE]
uv
adopted the PEP-735: dependency groups in pyproject.toml in only 15 days. https://github.com/astral-sh/uv/issues/8090
Do you realize how great this is? Before, you were only able to install dev
dependencies using uv
, but after the change, you can use whatever tool you
want, as long as they are Python-compliant, like pip
.
How to Upgrade Only One Dependency
https://docs.astral.sh/uv/guides/projects/#managing-dependencies
To upgrade a package, run uv lock with the
--upgrade-package
flag:
uv lock --upgrade-package requests
The
--upgrade-package
flag will attempt to update the specified package to the latest compatible version, while keeping the rest of the lockfile intact.
Running commands
|
|
How to migrate
You probably already have most of the files needed and use pip
:
setup.py
pyproject.toml
- be sure you have a
requires-python
entry or.python-version
- be sure you have a
requirements.txt
I would recommend fully migrate
setup.py
topyproject.toml
.
In that case, you can use the following commands:
uv venv
uv pip install -r requirements.txt
source .venv/bin/activate
python -V
In case you want to switch to pure uv
management you can try this:
uv add -r requirements.txt
git add uv.lock pyproject.toml
uv sync
from now on
To move from poetry
to uv
, use the requirements.txt
standard to migrate
dependencies:
poetry export --without-hashes -o requirements.txt
uv add -r requirements.txt
poetry export --dev --without-hashes -o requirements-dev.txt
uv add -dev -r requirements-dev.txt
git add uv.lock pyproject.toml
- remove poetry tables from
pyproject.toml