Skip to content

1.2. uv

What is uv?

uv is an extremely fast Python package installer, resolver, and project manager developed by Astral, the team behind the Ruff linter. Written in Rust, it's engineered for performance and serves as a single, cohesive toolchain, replacing pip, pip-tools, venv, pipx, and pyenv. By integrating these functionalities, uv simplifies and accelerates nearly every aspect of Python development, from initial setup to production deployment.

Why is uv a game-changer for MLOps?

For MLOps professionals, uv offers critical advantages that address common pain points in the ML lifecycle:

  • Unmatched Speed: uv is orders of magnitude faster than pip. This dramatically reduces CI/CD pipeline times, accelerates Docker image builds, and enables quicker iterative development—essential for the fast-paced nature of MLOps.
  • Unified Toolchain: It replaces a fragmented set of tools with a single, consistent interface. This simplifies environment management, dependency resolution, and package installation, leading to more reliable and maintainable workflows.
  • Advanced Caching: uv employs a sophisticated global caching system. This avoids redundant downloads and builds, ensuring that subsequent operations are nearly instantaneous—a significant benefit for reproducible research and consistent deployments.
  • Drop-in Compatibility: Designed as a drop-in replacement, uv can be adopted with minimal changes to existing scripts and workflows, allowing for a seamless transition.
  • Modern Project Management: uv fully supports pyproject.toml, enabling robust project and dependency management in line with modern Python standards.

How do you install uv?

Installing uv is simple. The recommended method uses an official script that handles platform detection and installation automatically:

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

Alternatively, you can use pip or pipx if you have them installed:

# Using pip
pip install uv

# Using pipx
pipx install uv

Verify the installation by checking the version:

uv --version

How can uv replace pip?

uv mirrors the most common pip commands, making it an intuitive substitute.

  • Installing packages:
uv pip install requests numpy pandas
  • Installing from a requirements file:
uv pip install -r requirements.txt
  • Generating a requirements file:
uv pip freeze > requirements.txt
  • Uninstalling packages:
uv pip uninstall requests

How can uv replace venv?

uv streamlines virtual environment creation and management.

  • Creating a virtual environment:
# Creates a .venv directory in the current folder
uv venv

This command automatically finds your system's Python and creates a virtual environment. To use a specific Python version, use the --python flag (e.g., uv venv --python 3.11).

  • Activating the virtual environment:

Activation commands remain standard for your shell:

# For bash or zsh
source .venv/bin/activate

Once a virtual environment is active, uv commands like uv pip install will automatically use it.

How can uv replace pipx?

uv includes a tool command that replicates pipx functionality, allowing you to install and run Python-based command-line tools in isolated environments.

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

How can uv replace pyenv?

uv can download and manage different Python versions, removing the need for pyenv.

  • Installing a specific Python version:
uv python install 3.12
  • Listing available Python versions:
uv python list
  • Pinning a Python version for a project:

You can create a .python-version file in your project's root directory with a specific version number (e.g., 3.12.4). uv will automatically respect this file for all subsequent commands.

How does uv work with pyproject.toml?

uv is designed to work seamlessly with pyproject.toml, the standard for modern Python projects. When you run uv pip install in a project with a pyproject.toml file, uv will:

  1. Read Dependencies: Automatically detect and install the dependencies listed in the [project] and [project.optional-dependencies] sections.
  2. Manage Environments: Create and sync a virtual environment with the exact dependencies specified in the uv.lock file (if present) or pyproject.toml.
  3. Lock Dependencies: Generate a uv.lock file that pins the versions of all direct and transitive dependencies, ensuring fully reproducible builds.

This makes uv a powerful tool for managing complex projects without needing higher-level workflow managers.

Additional Resources