uv Cheatsheet
204 words
One minute

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
- Create
<script_name>.py
- Initialize:
1
|
uv init --script <script_name>.py
|
Application Project
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:
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
Code Quality
Traditional:
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>
|