This release is a pre-release and may not be stable for production use.
py-build-cmake
A modern, PEP 517 compliant build backend for creating Python packages with extensions built using CMake.
In short, the task of a build backend is to make your Python project
pip installable.
For Python projects that incorporate native code, this may include compilation
or other build steps, which often require the invocation of tools like CMake.
Specifically, py-build-cmake performs the following tasks:
- It reads the project metadata and configuration options from the
standard
pyproject.tomlfile of your Python project. - It creates source distributions (sdists) of your project that can be shared with others (e.g. by uploading them to PyPI).
- It drives the CMake build process (e.g. for compiling extension modules
written in C or C++) and bundles the results into a Wheel package that can
be
pip installed by others.
Features
- Building and packaging C, C++ or Fortran extension modules for Python using CMake
- Declarative configuration using
pyproject.toml(PEP 621) - Editable/development installations for Python modules (PEP 660)
- Easy integration with pybind11, nanobind and SWIG, with stable ABI support
- Stub generation for type checking and autocompletion
- Customizable CMake configuration, build, and installation options
- Support for installation of multiple configurations and components, across different Wheel packages
- First-class cross-compilation support
- Reproducible Wheels and source distributions
- No dependency on setuptools
- Compatible with cibuildwheel for building Wheels
Installation
The py-build-cmake package is available on PyPI:
pip install py-build-cmake
Documentation
The documentation can be found on https://tttapa.github.io/py-build-cmake.
A quick start guide is available on the First Steps page.
It goes over the recommended file structure, and discusses a basic configuration.
More detailed examples can be found on the Examples page
The format of the pyproject.toml configuration file is explained in the
Reference.
Alternatively, use the command-line interface
to get the documentation for all supported options:
py-build-cmake config format
Usage
If you don't have one already, add a pyproject.toml configuration file to your
project's repository. Specify the mandatory project metadata (PyPA: Declaring project metadata),
and tell py-build-cmake how to build your CMake project. For example:
[project] # Project metadata
name = "example-project"
requires-python = ">=3.8"
readme = "README.md"
license = "MIT"
license-files = ["LICENSE"]
dependencies = ["numpy"]
dynamic = ["version", "description"]
[build-system] # How pip and other frontends should build this project
requires = ["py-build-cmake~=0.6.0a3"]
build-backend = "py_build_cmake.build"
[tool.py-build-cmake.module] # Where to find the Python module to package
directory = "src-python"
[tool.py-build-cmake.sdist] # What to include in source distributions
include = ["CMakeLists.txt", "src/*"]
[tool.py-build-cmake.cmake] # How to build the CMake project
build_type = "RelWithDebInfo"
source_path = "src"
build_args = ["-j"]
install_components = ["python_modules"]
[tool.py-build-cmake.stubgen] # Whether and how to generate typed stub files
The README of examples/minimal
describes this configuration file in much more detail.
Then use pip, build
or another PEP 517 compatible frontend to build and/or install the package.
Build sdist and wheel packages you can upload to PyPI:
python -m pip install -U build
python -m build . # find the sdist and wheel file in the 'dist' folder
Install the package in the current environment:
pip install . # normal installation
pip install -e . # editable installation
Examples
As an introduction to py-build-cmake, see examples/minimal
for a detailed overview of the configuration files and the directory structure,
using a very simple Python module as an example.
For a more advanced, real-world example, see examples/pybind11-project
and examples/nanobind-project.
Alternatively, SWIG can also be used instead of pybind11 or nanobind, as
demonstrated in examples/swig-project.
If you are interested in packaging C/C++/Fortran programs using py-build-cmake,
have a look at examples/minimal-program.
See the examples folder for a full list of examples.
A full example that uses the Conan package manager for C++ dependencies, and that uses GitHub Actions to deploy the Wheel packages built by py-build-cmake to PyPI can be found in tttapa/py-build-cmake-example.
Projects using py-build-cmake
If you need more examples, you can look at the following projects using py-build-cmake as their Python build backend:
Alternatives and related tools
- scikit-build-core: alternative CMake build backend, successor of scikit-build
- meson-python: Meson build backend
- flit: pure-Python packaging tool and build backend
- hatchling: build backend of the Hatch project manager, supports build hooks
- poetry-core: pure-Python build backend for the Poetry package manager
- crossenv: tool to trick
setuptoolsinto cross-compiling by monkey patching thesysconfiganddistutilsmodules
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_build_cmake-0.6.0a3.tar.gz.
File metadata
- Download URL: py_build_cmake-0.6.0a3.tar.gz
- Upload date:
- Size: 88.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f522b2a955d54f270ae934a0c57db69ff2eb98eb49debcc712e1278893e5203
|
|
| MD5 |
7eed7a181097c83f2d70a8c3ac9d53f3
|
|
| BLAKE2b-256 |
c02ef737565d7a61562233085f8bbeadabdc4ef908c7679b9fd7485fd2db3ab9
|
Provenance
The following attestation bundles were made for py_build_cmake-0.6.0a3.tar.gz:
Publisher:
wheel.yml on tttapa/py-build-cmake
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_build_cmake-0.6.0a3.tar.gz -
Subject digest:
0f522b2a955d54f270ae934a0c57db69ff2eb98eb49debcc712e1278893e5203 - Sigstore transparency entry: 2566888317
- Sigstore integration time:
-
Permalink:
tttapa/py-build-cmake@10e75d35998bd26c407a561cc51ba0cc7a15d896 -
Branch / Tag:
refs/tags/0.6.0a3 - Owner: https://github.com/tttapa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yml@10e75d35998bd26c407a561cc51ba0cc7a15d896 -
Trigger Event:
release
-
Statement type:
File details
Details for the file py_build_cmake-0.6.0a3-py3-none-any.whl.
File metadata
- Download URL: py_build_cmake-0.6.0a3-py3-none-any.whl
- Upload date:
- Size: 112.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50cf7a7fc5b5a9e6ac373f5123e68d5a8b30068121f19618a547bf2d8243102d
|
|
| MD5 |
623f2fc0934fa737c3e603016949f99d
|
|
| BLAKE2b-256 |
2aaa858d146ad88e6f88bcb7c73f003b6750b5323ad681ea020030f57d7b7035
|
Provenance
The following attestation bundles were made for py_build_cmake-0.6.0a3-py3-none-any.whl:
Publisher:
wheel.yml on tttapa/py-build-cmake
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_build_cmake-0.6.0a3-py3-none-any.whl -
Subject digest:
50cf7a7fc5b5a9e6ac373f5123e68d5a8b30068121f19618a547bf2d8243102d - Sigstore transparency entry: 2566888379
- Sigstore integration time:
-
Permalink:
tttapa/py-build-cmake@10e75d35998bd26c407a561cc51ba0cc7a15d896 -
Branch / Tag:
refs/tags/0.6.0a3 - Owner: https://github.com/tttapa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheel.yml@10e75d35998bd26c407a561cc51ba0cc7a15d896 -
Trigger Event:
release
-
Statement type: