uv
¶
uv is an extremely fast Python package and project manager.
Both the installation of uv and the creation of file structures for libraries or Apps are already described in our Python basics tutorial.
Inline script metadata¶
However, uv
is also ideal for individual Python scripts that contain inline
script metadata,
for example:
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "rich",
# ]
# ///
import rich
If the permissions for the app.py
file are executable, for example with
chmod 755
, you can run it on any computer with uv
installed:
./app.py
A separate isolated environment is automatically created with the correct Python version and dependencies.
Create packages¶
With uv build you can easily create distribution packages and wheels.
Declare, lock and automatically update dependencies¶
Updating the Python environment describes how you can use uv lock --upgrade
to update
all dependencies and uv lock --upgrade-package PACKAGE==VERSION
to
update individual dependencies in a controlled manner. We describe how you can
regularly update the dependencies of your project automatically in
Dependency bot. These measures significantly increase the security of
your project.
Testing in different Python environments¶
uv simplifies the parallel installation of different Python versions, including PyPy and free-threaded Python 3.13. With tox-uv you can then test your project automatically in the different Python environments.