Building Python Wheels for Multiple Platforms
If your package is pure Python, one wheel serves everyone and you can skip most of this page. The moment it contains compiled code, whether C, C++, Rust or Cython, each operating system, CPU architecture and often each Python version needs its own wheel. Get the set wrong and users fall back to compiling from source, which fails on machines without a toolchain.
Reading a wheel filename
The filename encodes compatibility, and installers choose by matching these tags:
fastparse-2.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
| | | | |
name ver py abi platform
- Python tag (
cp312): built for CPython 3.12. A pure wheel sayspy3. - ABI tag (
cp312,abi3ornone): which binary interface the compiled code expects. - Platform tag:
manylinux_2_28_x86_64,musllinux_1_2_aarch64,macosx_11_0_arm64,win_amd64, oranyfor pure wheels.
The manylinux tags (defined in PEP 600) promise the wheel only needs a glibc at least as new as the version in the tag. musllinux (PEP 656) covers musl-based distributions such as Alpine. A wheel built on your own laptop's Linux usually does not qualify; it has to be built in, or repaired to match, the reference environment.
Building the matrix with cibuildwheel
cibuildwheel, maintained under the Python Packaging Authority, runs the build inside the official manylinux and musllinux containers on Linux and natively on macOS and Windows runners, repairs the wheels (with auditwheel or delocate) and runs your tests against each one. A minimal configuration lives in pyproject.toml:
[tool.cibuildwheel]
build = "cp310-* cp311-* cp312-* cp313-*"
skip = "*-win32"
test-requires = "pytest"
test-command = "pytest {project}/tests -q"
[tool.cibuildwheel.linux]
archs = ["x86_64", "aarch64"]
Building aarch64 on an x86 runner works through emulation but is slow; native Arm runners, where your CI offers them, cut that time considerably. Whatever you choose, run the tests against the built wheel rather than your source tree, so a missing compiled file or wrong tag fails the job.
Cutting the number of wheels
A full matrix of Python versions times platforms times architectures grows quickly. Two ways to shrink it:
- The stable ABI. If your extension sticks to the limited C API, one
abi3wheel built for your oldest supported Python works on newer versions too. Rust bindings built with PyO3 and maturin support this as an option. - Drop combinations nobody runs. 32-bit Windows and very old Python versions are common candidates. Say in the README which platforms get wheels, so users on others know to expect a source build.
Always upload the sdist too
The source distribution is the fallback for every platform you did not build for, and it is what downstream redistributors such as Linux distributions often start from. Build it in the same workflow (python -m build --sdist), check that it compiles from a fresh clone, and upload it with the wheels. Publishing all artefacts from one job, using Trusted Publishing, avoids a window in which some platforms have the new version and others do not.
Release-day checklist
- Wheels exist for every platform the README promises.
- Each wheel installed and passed tests in a clean environment.
- The sdist builds without network access to your repository.
- Version metadata matches across all files; a quick look at the upload list catches a stray file from an old build directory.
For the surrounding project setup, see the pyproject.toml self-study course.