Contents

uv Cheatsheet

UV Package Manager Cheatsheet

Installation

1
curl -LsSf https://astral.sh/uv/install.sh | sh

Python Version Management

Traditional:

1
2
pyenv install 3.12
pyenv versions

UV Method:

1
2
uv python install 3.12
uv python list

Project Initialization

Script Project

  1. Create <script_name>.py
  2. Initialize:
1
uv init --script <script_name>.py

Application Project

1
uv init <app_name>

Structure:

1
2
3
4
5
6
7
<app_name>/
├── .git/
├── .gitignore
├── .python-version
├── README.md
├── hello.py
└── pyproject.toml

Library Project

1
uv init --lib <package_name>

Structure:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<package_name>/
├── .git/
├── .gitignore
├── .python-version
├── pyproject.toml
├── README.md
└── src/
    └── <package_name>/
        ├── __init__.py
        └── py.typed

Package Management

Installing Packages

Traditional:

1
pip install <package>

UV Method:

1
2
3
uv add <package>
# or
uv pip install <package>

Running Scripts

Traditional Method

1
2
3
python3 -m venv venv/
source venv/bin/activate
python3 <script.py>

UV Method

1
uv run <script.py>

Development Tools

Code Quality

Traditional:

1
2
flake8
black

UV Method:

1
2
uvx ruff check
uvx ruff format

Testing

1
2
uv add pytest --dev
uv run pytest

Publishing

Traditional Method

1
2
python3 -m build
python3 -m twine upload

UV Method

1
2
uv build
uv publish --token <PYPI_TOKEN>