Skip to main content

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.

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.

The format of the configuration file is explained in Config.md.

Alternatively, use the command-line interface to get the documentation for all supported options:

py-build-cmake config format

To get started quickly, have a look at the following section and the README in examples/minimal, which goes over the project structure and the configuration files you'll need.

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.5.1"]
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.5.1.tar.gz (75.2 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.5.1-py3-none-any.whl (97.3 kB view details)

Uploaded Python 3

File details

Details for the file py_build_cmake-0.5.1.tar.gz.

File metadata

  • Download URL: py_build_cmake-0.5.1.tar.gz
  • Upload date:
  • Size: 75.2 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.5.1.tar.gz
Algorithm Hash digest
SHA256 31a83b12fcc5fddee4d84f36c2d9a2954eb1a7907f5a9cb06f439232859ce513
MD5 67c4ed31d5d6daab9c6ff1b3b7814e52
BLAKE2b-256 6d556334f07a7772620130feb1300db0ff39f5c9385e3e6a94090d800353e3f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_build_cmake-0.5.1.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.5.1-py3-none-any.whl.

File metadata

  • Download URL: py_build_cmake-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 97.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for py_build_cmake-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78d5f2117169644f44d0d99d3a5e97fa9dc0b1458d8eccb96c46b5e15fecb8e7
MD5 a6f1184bd3c11f1d356e5dee9c97e663
BLAKE2b-256 152558eb111c349f631f5a664c293dffdd6036197e70f818c2e198ae32e116ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_build_cmake-0.5.1-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.5.1 This release

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