Skip to main content

Modern, PEP 517 compliant build backend for creating Python packages with

Project description

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.7"
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.0"]
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

Project details


Release history Release notifications | RSS feed

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.0.tar.gz (74.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.5.0-py3-none-any.whl (97.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_build_cmake-0.5.0.tar.gz
  • Upload date:
  • Size: 74.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.5.0.tar.gz
Algorithm Hash digest
SHA256 85f04cc28a051adafb8100d36e50f1a6f122ea559f237106fdc036ecaa44963b
MD5 24822928063308ac9d76d25280a70b55
BLAKE2b-256 2b5521e9ecb1546d6145dc37f9901d8e98e2c90da47b7882282c2eacd0f580e7

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: py_build_cmake-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 97.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8132c443bcec2431ce72247e5e6d651bb29313a9696b456e558c8d584fff6517
MD5 fe54a821d743f36e3bb3a82c3d2261a7
BLAKE2b-256 21298b9dfdb2ce82e068c04c9013d307c1bdd85c4f77c82715d70411ef4ae37d

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_build_cmake-0.5.0-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.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page