Why uv
Context and problem statement
Managing the packages we depend on when building Python packages isn’t “simply” installing it on your computer. The issue with installing Python packages on your computer is dependency conflicts that occur, where the “dependency trees” of one package require a different dependency tree than another one. So installing a package that requires a specific version of one package, while another package you already have installed requires another version can cause system problems.
The solution to this problem is by using “virtual environments” in Python. These are environments that are separate from the rest of the system and can install any packages without impacting other environments.
There are multiple ways of creating these virtual environments and managing package dependencies, and the optional solution depends on the project. So the question is:
What package dependency management tool should we use for our Python projects?
Decision drivers
- Package dependency management is a critical task, so we need a tool for it.
- Ensuring we have some way of building our Python projects in a way that is less likely to be a “it works on my computer” issue.
Considered options
There are (unfortunately) multiple tools to manage package dependencies. See the list of resources below for all the different options available. We’ll only cover these more popular tools as they fit our basic principles the most:
There’s also a very new tool that isn’t listed on many comparison pages but has already gained a lot of attention and been adopted by many projects because of how well designed it is and the problems it solves. So we will also consider it:
Pipenv
Pipenv was designed to combine the existing functionality of pip
and virtualenv
, rather than being designed and built specifically for the purpose of package management.
Benefits
- Is very popular and widely used
- Has been around for a while
- Only handles package dependencies (no other features)
Drawbacks
- Design is a bit older and not as intuitive/clear to use
- document is a bit too verbose/technical
- Package caching doesn’t seem to be well designed/robust, so packages could get unnecessarily re-installed
- Only handles package dependency management, which means we need another tool to develop software (like a Python package)
Poetry
Poetry was built and designed to address some of the short comings of pipenv and is specifically designed with package management and project development in mind.
Benefits
- Popular and widely used
- Very well designed website and documentation
- Handles package dependencies with lock files (detailed list of packages and versioning)
- Can set up and help manage a Python project (e.g. Python package)
- Designed from the ground up to consider the needs of package development and dependency resolution
- Allows for external plug-ins for further customization
- Similar dependency management to other languages
- Installable with
pipx
- Integrates well with existing IDE/editors (PyCharm and VSCode)
- Versions below 2.0.0 were not completely PEP compliant (not yet support PEP 621, but an Issue on it is here), but after 2.0.0 it is PEP compliant
Hatch
Hatch, like Poetry, was designed to manage package dependencies and Python projects.
PDM
PDM, like both Poetry and Hatch, is designed for managing packages and Python projects.
uv
uv is a new tool that was designed from the ground up to directly solve many of the dependency management issues found in Python, rather than try to refactor existing tools. It is also written in Rust and is extremely fast.
Benefits
- Has all the same benefits as Poetry above
- The command line interface is very simple and easy to use
- Is very fast at resolving dependencies and installing the necessary packages
- Can install Python from its interface
- Will automatically detected the Python version need for a project in the
pyproject.toml
file and install the needed version. - Fully PEP compliant
- It simplifies many of the common project management tasks, often doing them automatically in the process of doing other tasks
- Is designed to be an easy replace for common tools like
pip
Decision outcome
We decided on uv because it has amazing documentation, is fast, is very well-designed, and is already being recommended by many in the community to be used over other tools.
Consequences
- It is still fairly new, but seems to already be very well designed. So we may encounter issues because it is still new, but we expect that it will be well supported and maintained in the future.