Build Backends: setuptools vs hatchling
The previous lesson showed that a backend is any module implementing PEP 517's hooks. In practice you choose among a handful. They all read the same [project] table and all produce standard wheels; they differ in how they decide which files go in, how they get the version, whether they can compile extensions, and how much legacy they carry.
| Backend | build-backend |
Strengths | Watch out for |
|---|---|---|---|
| setuptools | setuptools.build_meta |
the original; compiles C/C++ extensions; supports every old project (setup.py, setup.cfg) |
package auto-discovery rules, MANIFEST.in, *.egg-info folders, lots of output |
| hatchling | hatchling.build |
modern defaults, quiet, plugins (version from VCS, build hooks), the default of hatch new |
no compiled extensions without a plugin |
| flit-core | flit_core.buildapi |
minimal, zero dependencies, pure-Python only | few knobs by design |
| poetry-core | poetry.core.masonry.api |
what Poetry projects use; reads [tool.poetry] too |
Poetry-specific extras |
| uv_build | uv_build |
very fast, strict, the default of uv init --lib |
pure Python only, expects the src/<name> layout |
| scikit-build-core, meson-python, maturin | C/C++ (CMake), Meson, and Rust extensions |
The same project, two backends
Here is one small src-layout project with a README and a tests/ folder, built once with setuptools and once with hatchling. Only [build-system] differs:
bash · try it yourself
python3 -m venv .venv && . .venv/bin/activate
pip install -q build
make_project() {
mkdir -p "$1/src/tally" "$1/tests" && cd "$1"
printf '[build-system]\nrequires = ["%s"]\nbuild-backend = "%s"\n\n' "$2" "$3" > pyproject.toml
printf '[project]\nname = "tally"\nversion = "1.0.0"\nreadme = "README.md"\nrequires-python = ">=3.13"\n' >> pyproject.toml
echo 'def count(xs): return len(xs)' > src/tally/__init__.py
echo '# tally' > README.md
echo 'def test_ok(): pass' > tests/test_tally.py
python -m build -q 2>&1 | tail -1
echo "wheel:"; unzip -Z1 dist/*.whl | sed 's/^/ /'
echo "sdist:"; tar tzf dist/*.tar.gz | grep -v '/