uv — ultra-fast Python package manager
💬 "uv command"
uv is a ultra-fast Python package manager, a Python package management and execution tool built with Rust. It is dozens of times faster than pip.
As it is built on Rust, it provides 10~100x faster installation compared to pip. It includes built-in virtual environment creation and management (virtualenv is not required).
- Concept: Being built on Rust, it offers installation 10~100x faster than pip.
- Key Features: Includes built-in virtual environment creation and management (virtualenv is not required).
- Advantages: Pins dependencies with pyproject.toml and uv.lock.
- Usage: Also downloads and manages Python itself (replacing pyenv).
Installation and Download
uv is installed via a package manager or an official script.
| Environment | Command | |
|---|---|---|
| Official Script (Linux/macOS) | curl -LsSf https://astral.sh/uv/install.sh | sh |
| macOS (brew) | brew install uv | |
| pip (legacy) | pip install uv | |
| Rust cargo | cargo install uv | |
| Verify | uv --version |
You can verify the installation with uv --version.
Common Options
| Option | Description |
|---|---|
| uv init | Initialize a new project |
| uv add <pkg> | Add a dependency and update the lock file |
| uv run <cmd> | Run a command inside the virtual environment |
| uv venv | Create a virtual environment |
| uv pip install <pkg> | A pip-compatible install command |
Essential Command Combination 3
uv init myapp && cd myapp— Initialize a new projectuv add fastapi uvicorn— Add dependenciesuv run python main.py— Execute in the virtual environment
💬 "Show me an example of using uv on a real server."
Here are common situations encountered on production servers, presented in order.
Step 1 · Verify Installation
Check if it is installed.
uv --version || curl -LsSf https://astral.sh/uv/install.sh | sh
Step 2 · Create Virtual Environment
Create the project's virtual environment.
cd /var/www/app && uv venv
Step 3 · Install Dependencies
Install the existing requirements.txt.
uv pip install -r requirements.txt
Actual Execution Screen
This shows the result of creating a virtual environment and installing dependencies using uv.
A production server
How It's Used in Practice
1. Migrating an Existing pip Project
Scenario — Migrating an existing requirements.txt to uv.
uv venv && uv pip install -r requirements.txt
Result — 24 packages are installed in 120ms.
Key Point — Build time is reduced from tens of seconds to tens of milliseconds.
2. Ensuring Reproducibility in CI
Scenario — Introducing uv into the CI pipeline.
uv add fastapi && uv run pytest
Result — Reproducible installation is possible with uv.lock.
Key Point — The uv.lock file must always be committed to git.
Actual Execution Screen
This shows the result of running an application with uv run.
!uv command execution result 2
A production server
Points to Note
- The uv.lock file must always be committed to git. Without it, reproducibility is lost.
- To avoid conflicts with globally installed packages from pip, use it only inside a virtual environment.
- In corporate firewall environments, setting a PyPI mirror (--index-url) may be necessary.
Source (HTML): https://games.aidebatehub.com/programs/linux/modern/uv.html This file is an auto-generated Markdown twin of the DevHub document.
AI Knowledge Hub
Visitor Comments