All Articles
Technical 5 min read

UV Package Manager Implementation

Task: Migrate Python project to UV package manager

Quick Start:

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

# Create new project
uv init my-project
cd my-project

# Add dependencies
uv add fastapi uvicorn pydantic

# Add dev dependencies
uv add --dev pytest black ruff

# Install all dependencies
uv sync

# Run scripts
uv run python main.py

Key Features:

  1. 10-100x faster than pip/poetry for dependency resolution and installation
  2. All-in-one tool: Replaces pip, poetry, pyenv, virtualenv, pip-tools
  3. Written in Rust: System-level performance with parallel downloads
  4. Lock files: Automatic uv.lock generation like package-lock.json
  5. Python version management: uv python install 3.12 - no pyenv needed

Common Commands:

  • uv init - Create new project with pyproject.toml
  • uv add <package> - Add dependency to pyproject.toml and install
  • uv add --dev <package> - Add development dependency
  • uv sync - Install all dependencies from pyproject.toml
  • uv run <command> - Run command in virtual environment
  • uv python install <version> - Install Python version
  • uv python pin <version> - Set project Python version
  • uv lock --upgrade - Update lock file with latest versions
  • uv cache clean - Clear package cache

Migration from Poetry:

# UV can read poetry's pyproject.toml directly
uv sync  # Just works!

Migration from pip:

uv init
uv add $(cat requirements.txt)
uv sync

Performance: UV achieves dramatic speedups:

  • Django installation: 15s (pip) → 1.5s (UV) = 10x faster
  • FastAPI deps resolution: 45s (pip) → 2s (UV) = 22x faster
  • Cold cache install: 120s (pip) → 8s (UV) = 15x faster

Use UV for new projects and consider migrating existing projects with slow CI/CD pipelines.

If you’ve been frustrated with slow pip install commands or juggling between pip, poetry, virtualenv, and pyenv, there’s game-changing news. UV is here to revolutionize how you manage Python projects.

Created by Astral - the team behind the blazingly fast Ruff linter - UV is an extremely fast Python package and project manager written in Rust. Released in February 2024, it’s already transforming how developers work with Python dependencies.

The Bold Promise

UV claims to be 10-100x faster than traditional tools. Sounds too good to be true? The benchmarks don’t lie.

Why This Matters

In modern development, you might run pip install dozens of times per day. If each installation takes 2 minutes instead of 10 seconds, that’s 25 minutes of wasted time daily. UV eliminates this bottleneck.

The Problem with Traditional Tools

Every Python developer knows the pain:

  • pip: Slow dependency resolution, no lock files by default
  • poetry: Great features but painfully slow on large projects
  • pipenv: Dependency resolution can take forever
  • pyenv + virtualenv + pip-tools: Too many tools to juggle

You end up with a complex toolchain that slows down your workflow and CI/CD pipelines.

The UV Solution: One Tool to Rule Them All

UV replaces ALL of these tools with a single, blazingly fast solution:

# Instead of this mess:
pyenv install 3.12
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip-compile requirements.in

# You do this:
uv sync
Developer Experience Win

UV automatically manages virtual environments, Python versions, and lock files. You focus on code, not tooling.

Performance: The Numbers Don’t Lie

Real-World Benchmarks

According to official benchmarks:

TaskpipPoetryUVSpeedup
Installing Django15s25s1.5s10x faster
Resolving FastAPI deps45s60s2s30x faster
Cold cache install120s180s8s22x faster

Real developers report dramatic improvements:

“Our CI/CD pipeline went from 8 minutes to 45 seconds after switching to UV”

Why So Fast?

  1. Written in Rust: System-level performance instead of Python
  2. Parallel Downloads: Fetches packages concurrently, not sequentially
  3. Smart Caching: Aggressive but intelligent caching strategy
  4. Optimized Resolver: Modern dependency resolution algorithms

Getting Started with UV

Installation (Takes 30 Seconds)

macOS/Linux:

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

Windows (PowerShell):

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

Alternative (via pipx):

pipx install uv

Verify installation:

uv --version

UV in Action: Common Workflows

1. Starting a New Project

# Create a new project
uv init my-awesome-project
cd my-awesome-project

# UV creates:
# - pyproject.toml (project config)
# - .python-version (Python version)
# - src/ directory structure

2. Managing Dependencies

Add packages:

# Add production dependencies
uv add requests fastapi pydantic

# Add development dependencies
uv add --dev pytest black ruff

This automatically:

  • ✅ Updates pyproject.toml
  • ✅ Creates/updates uv.lock (like package-lock.json)
  • ✅ Installs packages in your virtual environment

Remove packages:

uv remove requests

3. Installing Project Dependencies

# Install all dependencies from pyproject.toml
uv sync

# Install only production dependencies
uv sync --no-dev
Lock File Consistency

Always commit uv.lock to version control. This ensures everyone on your team uses identical dependency versions, preventing “works on my machine” issues.

4. Running Python Scripts

# UV handles virtual environment automatically
uv run python main.py

# Run with specific Python version
uv run --python 3.12 python main.py

5. Managing Python Versions

Yes, UV can even install Python for you:

# Install Python 3.12
uv python install 3.12

# List installed Python versions
uv python list

# Set project Python version
uv python pin 3.12

No more pyenv needed! 🎉

UV vs The Competition

FeaturepipPoetrypipenvUV
SpeedBaseline2-3x slower2-4x slower10-100x faster
Lock files
Python installation
Virtual environments
Script execution
Dependency resolutionBasicGoodSlowExcellent & Fast
Written inPythonPythonPythonRust 🦀

Real-World Use Cases

1. Speed Up CI/CD Pipelines

# GitHub Actions with UV
- name: Install dependencies
  run: |
    curl -LsSf https://astral.sh/uv/install.sh | sh
    uv sync
  # Goes from 5 minutes to 20 seconds! 🚀
CI/CD Impact

Faster CI/CD means faster feedback loops, more frequent deployments, and significant cost savings on compute resources.

2. Single-File Scripts with Dependencies

# script.py
# /// script
# dependencies = [
#   "requests",
#   "beautifulsoup4",
# ]
# ///

import requests
from bs4 import BeautifulSoup

# UV automatically installs deps when you run:
# uv run script.py

Based on PEP 723, UV can execute scripts with inline dependency metadata!

Migration Guide

From pip + requirements.txt

# Old way
pip install -r requirements.txt

# New way
uv init
uv add $(cat requirements.txt)
uv sync

From Poetry

# UV can read poetry's pyproject.toml!
uv sync  # Just works™

# Or convert explicitly
uv export --format requirements-txt > requirements.txt
Poetry Compatibility

UV is designed to be compatible with Poetry’s pyproject.toml format, making migration seamless for most projects.

From Pipenv

# Export Pipfile.lock
pipenv requirements > requirements.txt

# Import to UV
uv init
uv add $(cat requirements.txt)

Should You Switch to UV?

✅ Reasons to Switch

  1. Dramatic Speed Improvements: 10-100x faster
  2. Simplified Toolchain: One tool instead of 5+
  3. Active Development: Regular updates from Astral
  4. Great Documentation: docs.astral.sh/uv
  5. Growing Community: 25k+ GitHub stars
  6. MIT Licensed: Open source, permissive license

⚠️ Things to Consider

  1. Young Tool: Released in 2024 (rapidly maturing)
  2. Pre-1.0: API may evolve with breaking changes
  3. Learning Curve: New commands to learn (but simpler overall)

The Verdict

For new projects: UV is an excellent choice. Start with it.

For existing projects: Consider migrating if:

  • You have slow CI/CD pipelines
  • You’re frustrated with current tools
  • You want a simpler workflow

Advanced Features

1. Dependency Groups

Organize dependencies beyond just “dev”:

[dependency-groups]
test = ["pytest", "pytest-cov"]
docs = ["mkdocs", "mkdocs-material"]
lint = ["ruff", "mypy"]
uv sync --group test
uv sync --group docs

2. Override Dependencies

Force specific versions:

[tool.uv]
override-dependencies = ["numpy==1.24.0"]

3. Private Package Indexes

uv add --index-url https://pypi.company.com/simple package-name

Common Issues and Solutions

Issue 1: “uv command not found”

Solution:

# Add to PATH (in ~/.bashrc or ~/.zshrc)
export PATH="$HOME/.local/bin:$PATH"

# Reload shell
source ~/.bashrc

Issue 2: SSL Certificate Errors

Solution:

# Use system certificates
export UV_SYSTEM_CA_BUNDLE=true

Issue 3: Conflicting Dependencies

# Clear cache
uv cache clean

# Force re-resolve
uv lock --upgrade
Troubleshooting

If you encounter issues, check the UV GitHub issues - the community is active and responsive.

The Future of UV

Astral has big plans:

  • Better IDE Integration: VS Code, PyCharm plugins
  • Cloud Build Caching: Share cache across team
  • Enhanced Monorepo Support: Workspace improvements
  • Plugin System: Extensibility for custom workflows

Follow development: github.com/astral-sh/uv

Conclusion: Is UV Worth the Hype?

Absolutely yes.

UV isn’t just incrementally better - it’s a paradigm shift in Python tooling. The speed improvements alone make it worth trying, and the unified workflow is the cherry on top.

Getting Started Today

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

# Start your first project
uv init my-project
cd my-project
uv add fastapi uvicorn
uv run uvicorn main:app

# You're running 10x faster already! 🚀
Final Thoughts

Python tooling has been fragmented for too long. UV represents a new era where speed is default, simplicity wins, and one tool does it all well.

References

  1. uv: An extremely fast Python package and project manager Official UV GitHub repository with source code and documentation
  2. UV Documentation Complete official documentation for UV
  3. Managing Python Projects With uv Real Python's comprehensive guide to UV
  4. Python UV: The Ultimate Guide DataCamp's tutorial on using UV for Python package management
  5. Poetry Was Good, Uv Is Better Real-world MLOps migration story from Poetry to UV
  6. Comparing uv and pip Performance comparison between UV and pip
  7. PEP 723 – Inline script metadata Python Enhancement Proposal for inline dependency specification
  8. uv Benchmarks Official performance benchmarks and methodology
HT

Written by Hisham Tariq

Backend Engineer & AI Researcher passionate about building secure, intelligent systems at the intersection of cybersecurity and artificial intelligence. Specializing in Python, FastAPI, and machine learning.