Have you ever found yourself patiently waiting as Pip installs the various Python packages needed for your latest project? Well, the good folks at Astral aim to solve this common frustration with their new tool: uv!
What is Uv?
uv is a fast (10-100 times faster) high-speed package installer and dependency resolver for Python, developed in Rust, and is designed as a drop-in replacement for pip
, pip-tools
, and virtualenv
.
How to Install Uv
To install uv on macOS or Linux, run:
curl -LsSf https://astral.sh/uv/install.sh | sh
Further install options can be found here.
Using Uv
Creating a Virtual Environment
First, we can create a virtual environment using uv env
. This will create a virtual environment in your current directory named .venv
.
Create a virtual environment:
uv venv
# Using Python 3.10.4 interpreter at: /home/rick/.pyenv/versions/3.10.4/bin/python3
# Creating virtualenv at: .venv
# Activate with: source .venv/bin/activate
Activate a virtual environment:
source .venv/bin/activate
Installing Packages
Just like pip
we can install packages from a requirements.txt
or just via the package name, like so:
uv pip install <package_name>
# or
uv pip install -r requirements.txt
Locking Dependencies
To lock the current dependencies of the environment, you can either perform a standard freeze like so:
uv pip freeze > requirements.txt
Uv Caveats
Unlike Poetry and PDM, which generate platform-specific lock files, uv generates a platform-specific only requirements.txt
file.
Closing Thoughts
uv is a great tool, and a great addition to the Python development ecosystem. With its ability to easily be provided as a drop in replacement it makes it a great choice for reducing build and setup times in Docker environments and also CI/CD workflows.
Well, thats all from us, thanks for reading, and we'll see you in the next post!