Hatchling vs uv_build for pure Python packages

You start a pure Python package with uv, run uv init, and [build-system] already names uv_build. Or you are choosing a backend before the first commit and wonder whether hatchling is worth it if you plan to keep using uv every day. This post helps you decide: keep the default, switch to hatchling, or start with hatchling under uv from day one.

The post separates the uv frontend from the build backend. It compares hatchling and uv_build on features, what lands in the sdist, and the cost of building from source. It ends with a short keep-or-switch checklist.

This expands the rule from Build backends for pure Python packages: prefer hatchling, and use uv_build only while the package stays simple and static. The scope here is pure Python. For compiled packages, see Build backends when your package is not pure Python.

You can keep uv and still use hatchling

The uv CLI is a frontend. The build backend is the program named in [build-system]. They are separate choices.

uv sync, uv lock, and uv build all drive whatever backend you declare. Picking hatchling is not “leaving uv.” It is only changing which tool turns your source tree into an sdist and a wheel:

[build-system]
requires = ["hatchling >= 1.26"]
build-backend = "hatchling.build"

Starting a new project and already planning to use uv? Create it with hatchling from the first commit:

$ uv init --build-backend hatch example-app

That keeps uv as the frontend and writes hatchling into [build-system], so you skip the default uv_build pin.

If you do want uv_build, the block looks like this:

[build-system]
requires = ["uv_build>=0.13.10,<0.14"]
build-backend = "uv_build"

uv init often pins both a minimum and a maximum uv_build version, because that package moves with uv. Astral recommends the upper bound so builds stay compatible as new uv_build releases ship. A minimum alone can work for a hand-written table; keep the upper bound if you want that recommended compat story.

What each backend can do

Hatchling supports static metadata and full dynamic metadata. A common next step is a version from a Git tag: add hatch-vcs and mark version as dynamic. Plugins and build hooks cover custom steps, such as an assembled README.

uv_build keeps metadata static. It has no plugin system and no build scripts. Anything that must appear in the wheel has to exist in the tree before the build starts. By default it expects one module under src/<package_name>/. You can change the module name and root with [tool.uv.build-backend], but you cannot grow into VCS versions or generated files.

Astral’s own build backend docs already point to hatchling when you need build scripts or a more flexible layout.

For a simple package, both backends can ship a fine py3-none-any wheel. The sharper differences are what goes into the sdist, and who pays when someone builds from source.

What lands in the sdist

An sdist is the source archive you upload. A wheel is what most users install. The backends diverge most on the sdist.

Hatchling’s default sdist follows the project tree and .gitignore. Tests and docs often travel with the archive.

uv_build is narrower. It ships the module plus files named in project metadata, such as the readme and license files. Tests and docs stay out unless you add them with source-include.

Here is the same tiny tree built twice: src/demo/ (with a CSV beside the code), tests/, docs/, README, and LICENSE. Only the [build-system] table changes. Hatchling’s sdist (file paths only):

$ tar tzf dist/demo-0.1.0.tar.gz
demo-0.1.0/.gitignore
demo-0.1.0/docs/index.md
demo-0.1.0/LICENSE
demo-0.1.0/PKG-INFO
demo-0.1.0/pyproject.toml
demo-0.1.0/README.md
demo-0.1.0/src/demo/__init__.py
demo-0.1.0/src/demo/table.csv
demo-0.1.0/tests/test_a.py

uv_build keeps the module and the declared readme and license. It adds a normalized pyproject.toml plus pyproject.toml.orig. Tests and docs are absent:

$ tar tzf dist/demo-0.1.0.tar.gz
demo-0.1.0/LICENSE
demo-0.1.0/PKG-INFO
demo-0.1.0/pyproject.toml
demo-0.1.0/pyproject.toml.orig
demo-0.1.0/README.md
demo-0.1.0/src/demo/__init__.py
demo-0.1.0/src/demo/table.csv

Wheels for a tiny package look almost the same either way. Distros and CI jobs that rebuild and test from the sdist feel the gap. Before you publish after a switch, list both artifacts (tar tzf on the sdist, unzip -l on the wheel) and confirm the files you expect are there.

Who pays for a Rust build backend

The usual pitch for uv_build is speed. The absolute gain is often tens to about 100 ms per build. For a release or a single CI job, that is rarely the deciding factor.

uv_build itself is a Rust binary. Its wheels are about 1.2 to 1.5 MiB per platform. Hatchling and flit-core are small pure-Python packages.

Michał Górny’s plea not to use uv-build explains the hit for source-based distros such as Gentoo. They rebuild a large Rust tool often, and Rust’s portability is weaker on niche architectures. People who install your wheel barely notice. People who build your sdist notice first.

That cost matters most for libraries you publish widely. It matters less for an internal app that never ships an sdist.

Practices if you stay on either side

If you use uv_build, treat the narrow defaults as a checklist:

  • Declare readme and license-files so those files actually ship.
  • Use [tool.uv.build-backend] source-include for anything outside the module that packagers or CI need from the sdist, such as tests, docs, or tox config.
  • Keep the version static. If you need a Git tag version or generated files, switch to hatchling.
  • Before you publish, list the sdist and wheel and confirm the contents.

graphql-core shows the source-include pattern well. It declares uv_build, then lists tests/**, docs/**, tox config, and related files so the sdist stays useful downstream.

If you stay on hatchling and care what the sdist carries, start from the broader default, then narrow it. pydantic keeps hatchling (with hatch-fancy-pypi-readme) and sets an explicit sdist include list so the archive does not grow without review. Same concern as graphql-core, approached from the other side.

When to choose which

Prefer hatchling for a new pure-Python package, especially a library on PyPI. You get room to grow, sdist defaults you can trim later, and a small pure-Python build dependency for people who build from source.

Use uv_build only when all of these hold:

  • The package is pure Python.
  • Metadata stays static.
  • The default (or lightly configured) layout fits.
  • You accept the sdist and downstream costs above, or the package is mainly for your own apps and CI.

Need a Git tag version, a build hook, or a more flexible layout? Stay on hatchling. Already using uv day to day? Keep uv. Start with uv init --build-backend hatch, or change only the [build-system] lines if you switch later. For this class of package, that switch is usually a small config change.

Further reading

Leave a Reply