Kritim Yantra
Apr 21, 2025
UV, the Rust-powered Python package and project manager, is revolutionizing how developers build and manage Python applications. Built by Astral (creators of Ruff), UV combines blistering speed with modern workflows, making it ideal for beginners and experts alike. In this guide, you’ll learn how to write Python programs and run them successfully using UV’s powerful features. Let’s dive in!
pip
and pip-tools
, thanks to Rust’s performance optimizations and advanced caching.pip
, virtualenv
, poetry
, and more with a single binary.pip
-like commands with zero learning curve.UV can be installed via standalone scripts, pipx
, or package managers like Homebrew:
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
irm https://astral.sh/uv/install.ps1 | iex
# Verify installation
uv --version
uv init my_project && cd my_project
This generates a project structure with essential files like app.py
, requirements.txt
, and a .gitignore
.
uv venv .venv # Instantly creates a virtual environment
# Activate the environment
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
UV’s virtual environments are 80x faster than Python’s native venv
and fully compatible with existing tools.
Install packages using UV’s pip
-compatible interface:
uv pip install flask pandas # Install Flask and Pandas
uv pip freeze > requirements.txt # Lock dependencies
Need a specific version? Use constraints:
uv pip install "flask>=2.0.0"
Share your project? Let others replicate your environment:
uv pip sync requirements.txt # Installs exact versions from the lockfile
Create app.py
:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return {"message": "Hello from UV!"}, 200
if __name__ == '__main__':
app.run(debug=True)
UV simplifies execution with automatic dependency management:
uv run app.py
This command:
Open http://localhost:5000
to see your API in action! 🚀
Generate reproducible environments with uv pip compile
:
uv pip compile requirements.in -o requirements.txt
UV’s lockfiles work across macOS, Linux, and Windows, ensuring consistency in team workflows.
Use PEP 723 annotations to declare dependencies directly in scripts:
# /// script.py
# dependencies = ["requests"]
import requests
response = requests.get("https://api.github.com")
print(response.json())
Run it with:
uv run script.py # Installs `requests` automatically!
Install and switch Python versions without pyenv
:
uv python install 3.12 # Install Python 3.12
uv venv --python 3.12 # Create an environment with this version
Manage multi-package projects (e.g., a FastAPI app + shared libraries) with Cargo-style workspaces:
# pyproject.toml
[tool.uv.workspace]
members = ["libraries/*"]
Run commands in specific workspace packages:
uv run --package my_library
uv pip install --missing
to auto-install missing packages.uv pip compile --upgrade
to refresh resolutions.requirements.txt
by default. For cross-platform projects, use uv pip compile --platform-independent
.UV isn’t just a tool—it’s a paradigm shift. Whether you’re writing a simple script or managing a complex project, UV’s speed and simplicity will transform your workflow. Install it now and experience Python development at lightning speed ⚡.
curl -LsSf https://astral.sh/uv/install.sh | sh
Happy coding! 🐍✨
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google