Skip to content

1.2. uv

What is uv?

uv is an extremely fast Python package installer and resolver, written in Rust, designed to be a drop-in replacement for pip, pipx, venv, and pyenv. Created by Astral, the same team behind the high-performance linter Ruff, uv aims to significantly speed up and simplify Python project management. It offers a unified toolchain that handles virtual environments, dependency resolution, package installation, and more, all while providing exceptional performance.

Why should you use uv?

uv offers several compelling advantages for Python developers, especially in the context of MLOps:

  • Performance: uv is incredibly fast, often outperforming pip, venv, and pyenv by a significant margin. This speed translates to faster project setup, quicker dependency resolution, and reduced wait times during development and deployment.
  • Unified Toolchain: uv replaces multiple tools, simplifying your development workflow. It can manage virtual environments, install packages, and resolve dependencies, all within a single command-line interface.
  • Drop-in Replacement: uv is designed to be a drop-in replacement for common Python tools. This means you can often substitute uv commands for pip, venv, or pipx commands without altering your existing workflows significantly.
  • Active Development: Backed by Astral, uv is under active development with a focus on performance, reliability, and ease of use.
  • Cross-Platform Compatibility: uv works seamlessly across Linux, macOS, and Windows, ensuring a consistent experience regardless of your operating system.
  • Caching: uv implements aggressive caching mechanisms to avoid redundant work, further speeding up operations like package installation and environment setup.

How to install uv?

Installing uv is straightforward. The recommended method is to use the official installation script, which automatically detects your operating system and installs the appropriate version:

curl -LsSf https://astral.sh/uv/install.sh | sh

Alternatively, you can install uv using pip or pipx:

pip install uv
# or
pipx install uv

Once installed, verify the installation by checking the version:

uv --version

How to use uv as a drop-in replacement for pip?

uv can be used as a direct replacement for many common pip commands. Here's how:

  • Installing packages:
uv pip install requests numpy pandas
  • Uninstalling packages:
uv pip uninstall requests
  • Listing installed packages:
uv pip freeze
  • Updating packages:
uv pip install --upgrade requests
  • Installing packages from a requirements.txt file:
uv pip install -r requirements.txt

How to use uv as a drop-in replacement for venv?

uv can also replace venv for creating and managing virtual environments:

  • Creating a virtual environment:
uv venv

This command creates a new virtual environment in the .venv directory by default. You can customize the location using the --python flag to specify a Python interpreter path.

  • Activating the virtual environment:

The activation process depends on your shell. For example, on bash:

source .venv/bin/activate
  • Listing available Python interpreters:
uv venv --python

How to use uv as a drop-in replacement for pipx?

uv can also replace pipx for installing and managing globally available Python tools:

  • Installing a tool globally:
uv tool install ruff
  • Listing globally installed tools:
uv tool list
  • Running a tool without installing it:
uv tool run ruff --version

How to install a Python version with uv?

uv can also be used to install specific Python versions, similar to pyenv. This is particularly useful when you need to test your code against different Python environments or when a project requires a specific Python version that is not your system's default.

  • Installing a specific Python version:
uv python install 3.12

This command downloads and installs Python 3.12. You can then use this version to create virtual environments or run scripts.

  • Listing available Python versions:
uv python list
  • Listing installed Python versions:
uv python list --only-installed
  • Removing a specific Python version:
uv python remove 3.12

uv additional resources