uv - A Rust based package Manager for Python

Just like Rusts cargo, uv simplifies the managenment of Python projects. You can create virtual environments, run and build packages fast and easy.

Installing uv

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

Managing python project

Create a new project

In uv you create the whole virtual environment and initialise git with a single command.

$ uv init

This creates the following direcory structure

.
├── .git
├── .gitignore
├── .python-version
├── .venv
├── main.py
├── pyproject.toml
├── README.md
└── uv.lock

To run main.py just type

$ uv run main.py

To achieve the same with pip and python you have to execute the following command:

  1. Create a virtual environment

    $ python3 -m venv .venv

  2. Activate the virtual environment

    $ source .venv/bin/activate

  3. Initialise git version control

    $ git init

  4. Add a .gitignore

    $ touch .gitignore

  5. Add a README.md

    $ touch README.md

  6. Create a Python hello world file

    $ touch main.py

  7. Run your python file

    python main.py

Projects build file pyproject.toml

On uv init the following default toml is created

[project]
name = "foo"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.14"
dependencies = []

Create project environment with existing pyproject.toml

$ uv sync

This creates .venv if not created yet and a uv.lock which feezes the exact versions of dependencies and tools used in this project similar to pips freeze and makes the environment reprocucible.

$ pip freeze > requirements.txt

Adding dependencies

To add a dependency to a local project

$ uv add numpy

Using native python you would have to execute

$ pip install numpy

General and project independent tools should be installed with uvx

$ uvx ruff

Which is short for uv tool run and installs the dependencies globally.

Pinning a python version

$ uv python pin 3.14