Introduction
UV is a Python package manager that helps you manage your projects much more efficiently and faster. Instead of installing and using different tools such as pip and virtualenv, you can use those tools with UV. Besides that, you can also manage your virtual environment and dependencies.
Benefits of Using UV
- Speed and Efficiency: The fact that is like an all-in-one package, makes it faster and more productive to start/run a python project and managing it.
- Simplicity: It is much more simpler than using all the different tool for managing multiple projects. While you can just learn one package and use the commands of one project, to do the same thing you do with the other tools.
- Reliability: UV is really reliable in reproducing the same environment projects and start working on it, without running into issues.
How to Use It?
Installation
Check out the documentation to install UV based on your Operating System.
Managing Python Versions
You can install and use multiple versions of Python and change between them in a very efficient way.
For example write the following command to list all the available python versions for you to install:
uv python list
If you want to install a specific version, you enter:
uv python install [python version]
If you want a project to use a specific version:
uv python pin [python version]
You can uninstall a version:
uv python uninstall [python version]
Creating a Project and Virtual Environment
When you create a project using UV, it will start initializing the project and set up a virtual environment. That means any package or dependencies you install are confined within this project, and not installed globally.
For example, create a folder, open terminal and run:
uv init
You can see it creates a couple of files. These files help you manage the dependencies within this project scope.
You can also see that there is a file called hello.py
. To run a python file with UV, you run:
uv run hello.py
It will run the file, with the current version your UV is using.
Installing and Managing Dependencies
Now that you have created a project and know how to run it using UV. Let’s install a package and learn how to manage it.
To install a package you, run:
uv add "fastapi[standard]"
This command installs FastAPI package inside the project. You can see that it is installed inside pyproject.toml
.
[project]
name = "uv-test"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13.1"
dependencies = [
"fastapi[standard]>=0.115.6",
]
You can uninstall the package by running:
uv remove "fastapi[standard]"
You can see the dependencies tree:
uv tree
You can create a lockfile and make sure the exact version of your dependencies is installed accross different devices:
uv lock
There is more commands that could help you, but I just showed the basic commands that can get you started. Be sure to check the documentation, as it is very well written and helpful.