No history yet

Modern Tooling with uv

The Modern Python Toolkit

Python's tooling has a long history. For years, developers juggled a collection of separate tools: pip for installing packages, venv for creating virtual environments, and pip-tools for pinning dependencies. This worked, but it was often slow and clunky. Modern development demands speed and consistency, especially in automated environments like and containerized applications.

Enter uv. It's a single, incredibly fast tool that replaces the entire legacy toolkit. Written in Rust by the same team behind the linter Ruff, uv is designed to be a drop-in replacement for pip and venv, but it operates at a speed that feels revolutionary. It handles package installation, dependency resolution, and virtual environment management from one unified interface.

UV is a drop-in replacement for pip, pip-tools, and virtualenv, all rolled into one blazing-fast tool written in Rust.

Installation and Setup

Getting uv is straightforward. You can install it using pip, but the recommended way is with a standalone installer to keep it separate from any specific project's environment. On macOS and Linux, you can use curl:

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

For Windows, use PowerShell:

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

Once installed, uv can manage your project's virtual environment. Instead of manually creating one with python -m venv .venv, you can let uv handle it implicitly. The first time you run a command like uv pip install, it will automatically detect you don't have a virtual environment and create one for you in a .venv directory.

Unified Project Management

Modern Python projects centralize their configuration in a pyproject.toml file. This file is the single source of truth for project metadata, dependencies, and tool settings. uv embraces this standard completely.

You define your dependencies directly in pyproject.toml, just as you would with tools like Poetry or PDM.

[project]
name = "my-cool-project"
version = "0.1.0"
dependencies = [
    "fastapi>=0.110.0",
    "pydantic<3.0",
]

[project.optional-dependencies]
dev = [
    "pytest",
    "ruff",
]

With this file in place, you can install all project dependencies with a single command:

# Installs base dependencies
uv pip sync

# Installs dev dependencies as well
uv pip sync --all-extras

The sync command is key. It ensures your virtual environment has the exact packages specified, removing any that aren't required. This creates a clean, reproducible state every time.

Execution and Tooling

One of the biggest workflow changes uv introduces is moving away from activating virtual environments. Manually running source .venv/bin/activate is no longer the standard practice.

Instead, you use uv run to execute commands within the project's managed environment.

# Run your main application script
uv run python app/main.py

# Run your tests with pytest
uv run pytest

This approach guarantees that you're always using the correct Python interpreter and dependencies associated with your project, eliminating a common source of bugs. For one-off commands with packages that aren't installed in your environment, uv provides uvx, a powerful equivalent to pipx or npx.

# Run the latest version of cowsay without installing it
uvx cowsay "hello world"

Finally, let's talk about code quality. The uv author also created an extremely fast Python linter and formatter, also written in Rust. It can check your code for errors and reformat it to a consistent style in milliseconds.

Since Ruff is just another Python package, you can add it to your dev dependencies in pyproject.toml and run it via uv run.

# Check for linting errors
uv run ruff check .

# Automatically fix and format all files
uv run ruff format .

By integrating uv and Ruff, you establish a modern, high-performance development loop. Your dependencies are managed, your commands are consistent, and your code is clean and error-free from the moment you write it. This combination sets a new standard for Python development, focusing on speed, simplicity, and reproducibility.

Quiz Questions 1/6

What is the primary problem uv aims to solve in the Python ecosystem?

Quiz Questions 2/6

The recommended modern workflow with uv shifts away from manually activating a virtual environment. Instead, which command is used to execute scripts or commands within the project's managed environment?