Podcast Title

Author Name

0:00
0:00
Album Art

UV: The Blazing-Fast Python Package Manager Explained in 2 Minutes

By 10xdev team August 26, 2025
Listen

This article will guide you through setting up UV, an extremely fast Python package manager written in Rust. It serves as a single, comprehensive tool for managing Python versions, pip dependencies, virtual environments, and much more, all with a focus on speed and ease of use.

Why Choose UV?

UV is a powerful, all-in-one solution that simplifies your Python workflow. It combines the functionality of multiple tools into a single, cohesive interface. Here are some of its standout features:

  • Unified Tooling: Manage Python versions, virtual environments, and package installations without juggling different utilities.
  • Incredible Speed: Built in Rust, it offers a significant performance boost over traditional package managers.
  • Familiar Commands: It provides a pip interface, allowing you to use familiar commands like pip install.
  • Project Initialization: Quickly scaffold a new Python project with a standard structure.
  • Script-Specific Dependencies: Package dependencies for single Python scripts, making them portable and easy to run in isolated environments.

Installation

To install UV, simply run the following command in your terminal. It will automatically detect your operating system and install the appropriate version.

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

After the installation, you may need to restart your shell for the uv command to become available. Once you do, you can verify the installation by typing:

uv --version

Core Features Explained

UV offers a range of commands to streamline your development process:

  • uv init: Initializes a new Python project, creating a pyproject.toml, a main.py, and a README.md file.
  • uv venv: Creates a virtual environment, optionally with a specific Python version.
  • uv pip install: Installs packages into your environment using a familiar pip-like syntax.
  • uv run: Executes a Python script within an isolated environment, automatically managing its dependencies.
  • uv add: Adds dependencies to your pyproject.toml file.
  • uv python install: Installs different versions of Python, similar to pyenv.

Running Single-File Scripts

One of UV's most convenient features is its ability to run single Python scripts with their dependencies defined directly in the file. For example, consider a script that uses the requests library.

You can add a special comment to specify the dependency:

example.py ```python

/// script

requires-python = ">=3.8"

dependencies = [

"requests<3",

]

///

import requests

response = requests.get("https://astral.sh") print(response.status_code) ```

Next time you want to execute it, you can use uv to run the script. It will automatically create an isolated virtual environment, install the required packages, and then run the code. This makes sharing and running single-use Python scripts with a few dependencies incredibly simple.

Getting Started: A Practical Example

Let's walk through creating a new project and managing it with UV.

1. Create a Project Directory

First, create an empty directory for your project.

mkdir test-python-project
cd test-python-project

2. Initialize the Project

Run uv init to set up the project structure.

uv init

This command creates a main.py file, a pyproject.toml file, and a README.md. The pyproject.toml will contain basic project metadata and a section for dependencies.

pyproject.toml toml [project] name = "test-python-project" version = "0.1.0" description = "Add your description here" dependencies = [] requires-python = ">=3.8"

3. Create a Virtual Environment

Next, create a virtual environment for your project.

uv venv

This command creates a .venv directory in your project folder using your globally available Python version.

4. Activate the Environment

To activate the new environment, use the source command provided in the output.

source .venv/bin/activate

Your shell prompt should now indicate that the virtual environment is active.

5. Install Packages

To add packages, use the uv pip install command. Let's install numpy.

uv pip install numpy

UV will quickly resolve and install numpy and its dependencies. You can verify the installation by checking the installed packages.

uv pip list

This will show that numpy is now available in your environment. You can continue to install more packages as needed and run your Python files directly with uv run.

Join the 10xdev Community

Subscribe and get 8+ free PDFs that contain detailed roadmaps with recommended learning periods for each programming language or field, along with links to free resources such as books, YouTube tutorials, and courses with certificates.

Recommended For You

Up Next