UV. The Fastest Python Package Manager

Hello everyone! Recently I met a wonderful package manager UV. I want to introduce you to it too!

Hidden text

I didn't find any articles on Habr. There's nothing in the Russian segment of YouTube either. If that's not the case – sorry)

What is UV?

UV (website) is an extremely fast Python package manager written in Rust. It is designed as a replacement for pip and pip-tools. In addition, it can replace venv and pyenv. But first things first.

Benchmarks from developers

Benchmarks from developers

Benchmarks from developers are good, but I decided to check for myself how good it is. The measurements are very conditional and synthetic. They are made more for comparison than for real comparison. Time in seconds.

Team

pip

uv

Creating an environment

real

3,468

0.028

user

3,468

0,000

Installing flask

real

19,166

0.024

user

2,465

0,019

Installing requests (for comparison)

real

37,865

1,055

user

1,820

0.096

The results are quite worthy!

UV installation

On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh

On Windows.
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

For a specific version.
curl -LsSf https://astral.sh/uv/0.2.23/install.sh | sh
powershell -c "irm https://astral.sh/uv/0.2.23/install.ps1 | iex"

With pip.
pip install uv

With pipx.
pipx install uv

With Homebrew.
brew install uv

Creating an environment

uv venv

Activation of the environment

On macOS and Linux.
source .venv/bin/activate

On Windows.
.venv\Scripts\activate

Installing libraries

uv pip install flask # Ставим flask

uv pip install -r requirements.txt # Установка из requirements.txt

Fixing dependencies

uv pip freeze | uv pip compile - -o requirements.txt

What else can UV do?

The first is working with a virtual environment (I showed how to create an environment above).

Second, but not least, is Python version control. There is a project pyenv and I think UV will be able to push it aside here. In short, pyenv is a Python version control system on your computer. Let's say you have Python 3.10, and you want to install 3.8. You have two options – either download it from the official website and compile it, or install pyenv and use it to install the interpreter of the required version and create environments from it.

And here everything is in one tool!

1) Install the required version of Python

uv python install 3.12

2) Check that everything is installed

uv python list

3) Create an environment with a new version

uv venv -p /home/timur/.local/share/uv/python/cpython-3.12.3-linux-x86_64-gnu/bin/python3 venv2

source venv2/bin/activate

Voila! Now we have a new Python and a new environment for it.

Besides this, you can install utilities via uv tool, but to be honest, I didn’t really use it.

It is also possible to manage the package cache via uv cache.

As a result

Pros:

  • The biggest advantage is speed.

  • Syntax: If you know how to work with pip, then most of the commands will be familiar to you.

  • Working with virtual environment is a blast!

  • Working with Python versions is a blast!

There are also disadvantages:

  • Platform-dependent lockfile.

  • There is no fixation of the checksum of the dependent library as in the same poetry.

  • Until it is possible to see the dependency tree as in poetry.

UV is an interesting package manager. It is very fast and intuitive due to its similarity to pip. Virtual environment management and Python version control make UV a 3-in-1 tool, which only adds to its appeal. I think it can already compete with poetry and other large package managers.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *