In this lesson, you will learn how to use the [build-system] table in your pyproject.toml to specify exactly which tool is responsible for packaging your Python project.
The Problem with Old Packaging
Historically, Python packaging relied on setup.py scripts. These were essentially arbitrary code execution blocks that required a specific tool (usually setuptools) to be pre-installed. If you wanted to use a different, more modern build process, you were stuck because the installation process was tightly coupled to the build logic.
Enter PEP 517
PEP 517 introduced a standardized way for build tools (the "backends") to communicate with installation tools like pip. Instead of assuming a setup script exists, we now define the interface in pyproject.toml. This allows you to swap out your entire build system—for example, moving from setuptools to a faster, modern alternative like Hatch, Flit, or Poetry—without changing how users install your package.
Specifying Your Backend
To define a build backend, you use two required keys inside the [build-system] table: requires (the packages needed to build your project) and build-backend (the entry point for the build process).
Here is how you would configure your project to use Hatchling, the default backend for the Hatch project:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
When you run a command like python -m build, your installer looks at this table, creates an isolated temporary environment, installs hatchling, and then asks that tool to build your distribution files (the .whl or .tar.gz files). Because this process happens in isolation, the backend doesn't need to be installed in your global environment or your main project's virtual environment, keeping your dependencies clean and your build process predictable.
By offloading the "how-to" of packaging to a standardized backend, you ensure that your project can be built reliably on any machine, regardless of the local Python environment configuration.
Key Takeaway: PEP 517 allows you to decouple your project’s build logic from the installation tool by explicitly declaring your chosen build backend in the [build-system] table of your pyproject.toml.