Getting Started with uv: Fast Python Package Management and Project Initialization
This article introduces uv, a Rust‑based Python package manager, and demonstrates how to initialize a project with uv init, add dependencies with uv add, manage virtual environments via uv venv, and run tools with uvx, offering a faster, more automated alternative to pip and requirements files.
If you are used to pip install , manually creating virtual environments, and maintaining requirements.txt , you might find uv a pleasant surprise. uv is a Rust‑written Python package manager from the Astral team that can replace pip, venv, and pip‑tools while providing faster dependency resolution and a modern project workflow.
Initialize a project with uv init
Running the command creates a project skeleton in one step:
uv initCreate a .venv virtual environment;
Generate a pyproject.toml configuration file;
(Optional) Add initial dependencies;
Produce a uv.lock lock file;
Set .venv as the default environment for the current directory, eliminating the need to manually activate it.
The whole process replaces several manual steps with a single command, providing a cleaner starting point for Python projects.
Install dependencies with uv add (instead of pip install )
Traditional usage:
pip install requestsWith uv:
uv add requestsBenefits include:
Automatic entry of the dependency into pyproject.toml under [project.dependencies] ;
Installation into the .venv environment;
Automatic update of the uv.lock file;
No need to maintain a separate requirements.txt file.
For development dependencies, use:
uv add --dev pytest ruffTo remove a dependency:
uv remove requestsRun project scripts or tools with uv venv + uvx
uv places the virtual environment in .venv , but you do not need to source activate it each time. Simply execute:
uv venvThis ensures .venv exists and is automatically configured as the default Python environment for the current shell. Afterwards, any script runs without worrying about path issues.
uv also provides the uvx command, similar to pipx or Node.js's npx , allowing you to run CLI tools installed in the project directly. For example:
uvx ruff check .
uvx ruff format .Using uvx eliminates the need for global tool installations and extra wrappers like pre‑commit .
Example project structure
my-project/
├── .venv/ ← virtual environment
├── pyproject.toml ← project configuration (dependencies, metadata, etc.)
├── uv.lock ← locked dependency versions
├── main.py ← entry scriptPersonal experience
Adopting uv as the default tool for new projects brings several advantages:
No more manual requirements.txt files;
No conflict between poetry.lock and pyproject.toml ;
Dependency installation is 3–5× faster for large projects;
Combined with ruff as a lint‑and‑format solution, eliminating the need for black or flake8 .
In CI pipelines, replacing pip install -r requirements.txt with uv and its lock file yields more consistent environments.
Conclusion
If you are dissatisfied with slow pip install speeds, want to avoid maintaining multiple requirements files, and seek a modern, faster, and more automated Python project setup, give uv a try. Start your next project with uv init and enjoy the streamlined workflow.
Project homepage: https://docs.astral.sh/uv/
DevOps Engineer
DevOps engineer, Pythonista and FOSS contributor. Created cpp-linter, commit-check, etc.; contributed to PyPA.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.