python -m build: Build Distributions Command Reference
The standard, frontend-agnostic way to build distributions.
python -m build (the pypa/build tool) creates an sdist and a wheel in an isolated environment using the backend declared in pyproject.toml. It replaces "setup.py sdist bdist_wheel".
Common flags / usage
- python -m build -- build both sdist and wheel into dist/
- -w, --wheel -- build only the wheel
- -s, --sdist -- build only the source distribution
- -n, --no-isolation -- build in the current env (no isolated build)
- -o, --outdir DIR -- write artifacts to DIR
Example
shell
- run: python -m pip install build
- run: python -m build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/*In CI
build needs a [build-system] table in pyproject.toml declaring requires and build-backend; without it the build fails. Upload the dist/ artifacts so a later publish job can fetch and ship them.
Key takeaways
- python -m build produces an sdist and wheel in an isolated environment.
- It reads [build-system] from pyproject.toml to pick the backend.
- Upload dist/ as an artifact to hand off to a publish job.
Related guides
twine upload: Publish to PyPI Command ReferenceReference for twine upload in CI: publishing built distributions to PyPI or a private index, token authentica…
pip wheel: Build a Wheelhouse Command ReferenceReference for pip wheel in CI: building .whl archives for a project and its dependencies into a wheelhouse, t…
poetry build: Build Artifacts Command ReferenceReference for poetry build in CI: producing a wheel and sdist into dist/ from pyproject.toml, the --format fl…