DEV Community

Clément Dethoor
Clément Dethoor

Posted on

Introduction to UV

UV – Ultra Fast Python Package Manager

🧾 Overview

UV is an extremely fast Python project and package manager written in Rust.

  • Manages dependencies, virtual environments, and Python versions.
  • Can replace pip, pipx, pip-tools, or poetry.
  • Blazing fast due to being built in Rust.

⚙️ Installation

On macOS (via Homebrew)

brew install uv
Enter fullscreen mode Exit fullscreen mode

Using pip

pip install uv
Enter fullscreen mode Exit fullscreen mode

Enable shell auto-completion (e.g., for zsh)

eval "$(uv generate-shell-completion zsh)"
Enter fullscreen mode Exit fullscreen mode

Example: uv c[TAB] will autocomplete the command.


🚀 Setting Up a Project

Initialize a project

uv init --app my_app_name        # Default type (application)
uv init --package my_package_name
uv init --lib my_lib_name
Enter fullscreen mode Exit fullscreen mode

Run a script and create a virtual environment

uv run hello.py
Enter fullscreen mode Exit fullscreen mode

This will create a virtual environment automatically.

Add or remove dependencies

uv add pandas
uv remove pandas
Enter fullscreen mode Exit fullscreen mode

Sync environment and workspace

uv sync
Enter fullscreen mode Exit fullscreen mode

Upgrade a specific package

uv lock --upgrade pandas
Enter fullscreen mode Exit fullscreen mode

Show dependency tree

uv tree
Enter fullscreen mode Exit fullscreen mode

📦 Dependency Management (Workspaces)

UV supports workspaces, allowing you to manage multiple virtual environments in a single directory.

  • Running uv init inside an existing UV project creates a sub-project with its own virtual environment:
uv init new_project
uv add pandas
Enter fullscreen mode Exit fullscreen mode
  • To create a fully isolated project (not in the workspace):
uv init another_project --no-workspace
Enter fullscreen mode Exit fullscreen mode

🛠️ UV Tools

Run a tool (e.g., ruff)

uv tool run ruff check
Enter fullscreen mode Exit fullscreen mode

Check where tools are installed

uv tool dir
Enter fullscreen mode Exit fullscreen mode

Install a tool

uv tool install ruff
Enter fullscreen mode Exit fullscreen mode

🐍 Python Version Management

List available Python versions

uv python list
Enter fullscreen mode Exit fullscreen mode

Install a specific version

uv python install 3.12.0
Enter fullscreen mode Exit fullscreen mode

Set Python version for a virtual environment

uv venv --python 3.12.0
Enter fullscreen mode Exit fullscreen mode

Top comments (0)