No history yet

Modern Tooling with uv

A Faster Way to Manage Python

If you've been working with Python, you're familiar with the juggling act. You use pip to install packages, venv or virtualenv to create isolated environments, and maybe even pip-tools to pin dependencies. Each tool handles one part of the puzzle. This setup works, but it's not always fast or seamless.

Enter , a modern tool designed to unify this workflow. It's an extremely fast Python package installer and resolver written in Rust that aims to replace the entire collection of tools you've been using.

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

Because it’s a single binary, installation is simple. You can install it using pip, but it's often better to use a standalone installer to avoid conflicts.

# 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"

Once installed, you have a single command, uv, to manage nearly every aspect of your project's packaging and environment.

From Scripts to Projects

Moving from simple scripts to a structured project starts with a standardized configuration file. In modern Python, that file is pyproject.toml. Instead of manually creating a virtual environment and a requirements.txt file, you can initialize a new project with one command.

mkdir my-new-project
cd my-new-project
uv init

This creates a virtual environment in a .venv directory and generates a pyproject.toml file. This file is the new heart of your project, defining its name, dependencies, and other metadata. It's the successor to the old setup.py and requirements.txt combination.

[project]
name = "my-new-project"
version = "0.1.0"
description = "Add your description here."
requires-python = ">=3.8"
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

To activate the new environment, you use the same source command as you would with venv.

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

# On Windows:
.venv\Scripts\activate

Managing Dependencies and Pythons

With your project initialized and your environment active, you can start adding dependencies. This is where uv's speed really shines. Let's add Flask and Requests.

uv pip install flask requests

This command does two things: it installs the packages into your .venv and, more importantly, it updates your pyproject.toml file automatically. It also creates a lockfile named uv.lock. This file records the exact versions of every package and sub-dependency, ensuring that your project builds are perfectly reproducible anywhere.

Beyond packages, uv also manages Python versions. You can install new Python versions without needing external tools like pyenv.

# Install Python 3.12
uv python install 3.12

# Tell uv to use this version for the current project
uv python pin 3.12

This downloads the specified Python interpreter and configures your project's virtual environment to use it. It provides a single, unified toolchain for managing both your packages and your Python runtime, dramatically simplifying your setup.

Now you're ready to put your new knowledge to the test.

Quiz Questions 1/5

What is the primary goal of the uv tool in the Python ecosystem?

Quiz Questions 2/5

True or False: The uv tool is written in Python for seamless integration with existing projects.

By adopting uv, you streamline your development workflow, gain significant speed, and align your projects with modern Python standards.