Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

py-build-cmake
py-build-cmake

Python Wheel Documentation PyPI - Downloads

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:

  1. It reads the project metadata and configuration options from the standard pyproject.toml file of your Python project.
  2. It creates source distributions (sdists) of your project that can be shared with others (e.g. by uploading them to PyPI).
  3. 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.0a4"]
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 setuptools into cross-compiling by monkey patching the sysconfig and distutils modules

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_build_cmake-0.6.0a4.tar.gz (88.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_build_cmake-0.6.0a4-py3-none-any.whl (112.9 kB view details)

Uploaded Python 3

File details

Details for the file py_build_cmake-0.6.0a4.tar.gz.

File metadata

  • Download URL: py_build_cmake-0.6.0a4.tar.gz
  • Upload date:
  • Size: 88.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for py_build_cmake-0.6.0a4.tar.gz
Algorithm Hash digest
SHA256 19509f10148a1c73683b70dc02ca594500987ed522303770ae2df25cd198b719
MD5 fabee7ec01b29af91a24d2752e27f12d
BLAKE2b-256 9bef52243a2e07e6b684521742eb38917a354eb25c0bfd790e041ab2c7957002

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_build_cmake-0.6.0a4.tar.gz:

Publisher: wheel.yml on tttapa/py-build-cmake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_build_cmake-0.6.0a4-py3-none-any.whl.

File metadata

File hashes

Hashes for py_build_cmake-0.6.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 e749fe933ded67303fb18b03118ef3145959b336c70caeb3d3b3f071ab094e90
MD5 8863f5f753f202b00aa12a9461e3406e
BLAKE2b-256 e7b493093481bec1e78e7ccf4ba35539e347f8d41d3af0bc57c17c882f3dc52c

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_build_cmake-0.6.0a4-py3-none-any.whl:

Publisher: wheel.yml on tttapa/py-build-cmake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.6.0a4 This release

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.15

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11.post1

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

4 files

0.0.8

4 files

0.0.7

4 files

0.0.6

4 files

0.0.5

4 files

0.0.4

4 files

0.0.3

4 files

0.0.2

4 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page