Some Python Developers Are Switching to uv, Are You?

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:

  1. Performance: As mentioned, uv‘s Rust-based implementation allows for significantly faster package installations and dependency resolutions compared to pip.
  2. Integrated Environment Management: Unlike pip, which often requires pairing with tools like virtualenv for environment management, uv provides built-in support for creating and managing virtual environments.
  3. Comprehensive Project Handling: uv extends its capabilities to project initialization, dependency management, and script execution, offering a more holistic approach than pip.

Code Examples

Installing a Package with uv:

To install the requests library using uv:

uv pip install requests

This 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_project

This sequence creates a new directory with the necessary project files and structure.

Adding a Dependency:

To add flask as a dependency:

uv add flask

This 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.12

To 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 | sh

Alternatively, if you prefer using pip:

pip install uv

Once installed, you can initialize new projects, manage dependencies, and handle various aspects of Python project management through uv‘s commands.

From github:
Highlights

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

Leave a Reply