UV | Python Package Manager
For many managing packages and project environments in python has long been synonymous with tools like pip and virtualenv. However, there is a new package manager for Python — designed to replace multiple existing tools such as pip, virtualenv, pip-tools, pipx, poetry, and even parts of pyenv. It is not just a library — it is a standalone tool that provides a faster and more unified way to manage Python environments and dependencies.
It’s called uv and it’s here: github.com
Python commands can be found here: Working on projects | uv
Key Features of uv
Speed: One of uv‘s standout features is its speed. Benchmarks indicate that uv can be 10-100 times faster than traditional tools like pip. This performance boost is achieved through efficient dependency resolution and installation processes.
Unified Tooling: uv combines multiple functionalities into a single tool. This integration simplifies workflows, allowing developers to manage packages, create virtual environments, and handle project dependencies without juggling multiple tools.
Project Management: Beyond package installation, uv offers comprehensive project management features. Developers can initialize new projects, add dependencies, run scripts, and build distributions, all within the uv ecosystem.
Comparing uv to pip
While pip has been the standard for Python package installation, uv introduces several enhancements:
- Performance: As mentioned,
uv‘s Rust-based implementation allows for significantly faster package installations and dependency resolutions compared topip. - Integrated Environment Management: Unlike
pip, which often requires pairing with tools likevirtualenvfor environment management,uvprovides built-in support for creating and managing virtual environments. - Comprehensive Project Handling:
uvextends its capabilities to project initialization, dependency management, and script execution, offering a more holistic approach thanpip.
Code Examples
Installing a Package with uv:
To install the requests library using uv:
uv pip install requestsThis command installs the requests package into the project’s virtual environment.
Creating a New Project:
Initialize a new project named my_project:
uv init my_project
cd my_projectThis sequence creates a new directory with the necessary project files and structure.
Adding a Dependency:
To add flask as a dependency:
uv add flaskThis command updates the pyproject.toml file and installs flask in the virtual environment.
Python Version Compatibility
uv is designed to work with multiple Python versions. It can install and manage different Python versions as needed. For instance, to install Python 3.12 using uv:
uv python install 3.12To add flask as a dThis flexibility ensures that developers can manage projects across various Python versions seamlessly.
Getting Started with uv
To begin using uv, you can install it via the provided installation script:
curl -LsSf https://astral.sh/uv/install.sh | shAlternatively, if you prefer using pip:
pip install uvOnce installed, you can initialize new projects, manage dependencies, and handle various aspects of Python project management through uv‘s commands.
From github:
Highlights
- 🚀 A single tool to replace
pip,pip-tools,pipx,poetry,pyenv,twine,virtualenv, and more. - ⚡️ 10–100x faster than
pip. - 🗂️ Provides comprehensive project management, with a universal lockfile.
- ❇️ Runs scripts, with support for inline dependency metadata.
- 🐍 Installs and manages Python versions.
- 🛠️ Runs and installs tools published as Python packages.
- 🔩 Includes a pip-compatible interface for a performance boost with a familiar CLI.
- 🏢 Supports Cargo-style workspaces for scalable projects.
- 💾 Disk-space efficient, with a global cache for dependency deduplication.
- ⏬ Installable without Rust or Python via
curlorpip. - 🖥️ Supports macOS, Linux, and Windows.
uv is backed by Astral, the creators of Ruff.
Thank you for reading this article. I hope you found it helpful and informative. If you have any questions, or if you would like to suggest new Python code examples or topics for future tutorials, please feel free to reach out. Your feedback and suggestions are always welcome!
Happy coding!
Py-Core.com Python Programming
You can also find this article at Medium.com