uv Cheatsheet — Projects
Create a New Project
# Application (default — no build system)
uv init my-app
cd my-app
# Inside an existing directory
cd existing-dir
uv init
# Packaged application (with build system + src/ layout)
uv init --package my-lib
# Library (similar to --package, intended for distribution)
uv init --lib my-lib
# Specify Python version at creation time
uv init --python 3.12 my-app
# Use the uv build backend
uv init --build-backend uv my-pkgDefault Project Structure
After uv init my-app:
my-app/
├── .gitignore
├── .python-version
├── README.md
├── main.py
└── pyproject.tomlAfter uv init --package my-lib:
my-lib/
├── .gitignore
├── .python-version
├── README.md
├── pyproject.toml
└── src/
└── my_lib/
└── __init__.pyAfter first uv run or uv sync, additional files appear:
├── .venv/ # Virtual environment
└── uv.lock # Cross-platform lockfileThe pyproject.toml
Minimal generated file:
[project]
name = "my-app"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []For a packaged project, it also includes:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"Or with the uv build backend:
[build-system]
requires = ["uv_build>=0.7,<0.11"]
build-backend = "uv_build"Run Your Project
# Run the default entry point
uv run main.py
# Run with arguments
uv run main.py --verbose
# Run an installed executable from the environment
uv run -- pytest
uv run -- ruff check .
# Run with a specific Python version (overrides .python-version)
uv run --python 3.13 main.pyuv run automatically verifies the lockfile, syncs the environment, then executes. No manual activate needed.
Sync the Environment
# Install all dependencies from the lockfile
uv sync
# Include optional dependency groups
uv sync --group dev --group test
# Install all groups
uv sync --all-groups
# Sync without dev dependencies
uv sync --no-dev
# Freeze — don't update the lockfile first
uv sync --frozenLock Dependencies
# Regenerate the lockfile
uv lock
# Check lockfile is consistent (CI-friendly)
uv lock --check
# Upgrade everything to latest compatible
uv lock --upgrade
# Upgrade a single package
uv lock --upgrade-package requestsManual Virtual Environment Activation
If you prefer to activate the venv instead of using uv run:
uv sync
source .venv/bin/activate # bash/zsh
# .venv/bin/activate.fish # fishRead Project Version
uv version
# 0.1.0
# Set a new version
uv version 1.0.0