Skip to content

UV

https://docs.astral.sh/uv/

Usage

bash
# install global packages
uv tool install $package

# install python
uv python list
uv python install 3.7.1 3.11

# init project
uv python pin 3.11
uv init $project

# add package
uv add $package
uv add --dev $package
uv add --optional $group $package

# deps update
uv sync
uv lock --upgrade

# export to requirements.txt
uv pip compile pyproject.toml -o requirements.txt

Cookbooks

Specify project directory

toml
[tool.uv.build-backend]
module-root = "api"

Non-package

toml
[tool.uv]
package = false

Run tests against different python versions

bash
uv run --python 3.14 --isolated --with-editable '.[test]' pytest -n auto

Separate python version & venv per script

Add this at the top of python file:

python
# /// script
# requires-python = "==3.13"
# dependencies = [
#  "tqdm>=4.67.3",
# ]
# ///

References