uv Cheatsheet — Building & Publishing

·Updated March 20th, 2026

Build Your Package

bash
# Build sdist + wheel into dist/
uv build

# Build only the sdist
uv build --sdist

# Build only the wheel
uv build --wheel

# Build a specific workspace member
uv build --package my-lib

# Build to a custom output directory
uv build --out-dir build/

The build requires a [build-system] table in your pyproject.toml. Common backends include hatchling, setuptools, flit_core, pdm-backend, and uv_build.

The uv Build Backend

uv provides its own build backend optimized for speed:

toml
[build-system]
requires = ["uv_build>=0.7,<0.11"]
build-backend = "uv_build"

Create a new project using it:

bash
uv init --build-backend uv my-pkg

The backend supports src/ layout by default, namespace packages, multi-module packages, and custom include/exclude patterns.

Configure the uv Build Backend

toml
[tool.uv.build-backend]
# Explicitly set module name (defaults to normalized package name)
module-name = "my_module"

# Set the root directory for module discovery
module-root = "src"

# Include / exclude patterns (PEP 639 glob syntax)
source-include = ["tests/**"]
source-exclude = ["tests/fixtures/**"]

Publish to PyPI

bash
# Publish to PyPI (replaces twine upload)
uv publish

# Publish from a specific dist directory
uv publish dist/

# Publish to TestPyPI
uv publish --index-url https://test.pypi.org/legacy/

# Publish to a custom registry
uv publish --index-url https://my-registry.com/upload/

# Provide credentials via flags
uv publish --username __token__ --password pypi-XXXX

# Or via environment variables
export UV_PUBLISH_USERNAME=__token__
export UV_PUBLISH_PASSWORD=pypi-XXXX
uv publish

Typical Build & Publish Workflow

bash
# 1. Bump version
uv version 1.2.0

# 2. Build
uv build

# 3. Check the dist contents (optional)
ls dist/
# my_pkg-1.2.0.tar.gz
# my_pkg-1.2.0-py3-none-any.whl

# 4. Publish
uv publish

# 5. Tag the release
git tag v1.2.0
git push --tags

Build Isolation

By default, uv builds packages in isolation (a temporary environment with only declared build dependencies). For packages that need the project environment during build:

toml
[tool.uv]
no-build-isolation-package = ["cchardet"]

Extra Build Dependencies

When a package requires additional build dependencies not declared in its [build-system]:

toml
[tool.uv.extra-build-dependencies]
cchardet = ["cython"]
deepspeed = [{ requirement = "torch", match-runtime = true }]

The match-runtime = true option ensures the build dependency version matches what’s installed in the project environment.