Skip to content
Latchkey

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →