Skip to main content

Build Cub

pypi version Python 3.12+

A Hatch build hook for compiling native Python extensions. Supports Cython, PyBind11, Native C/C++, PyO3/Rust, and Gperf preprocessing with configuration-driven builds.

Features

  • Multiple Backends: Cython, PyBind11, Native C/C++, PyO3/Rust, and Gperf support out of the box
  • Configuration-Driven: All build settings defined in bear_build.toml
  • Cross-Platform: Automatic compiler/linker arg selection for Unix and Windows
  • Settings Inheritance: Define defaults once, override per-backend as needed
  • Flexible Templates: Generate version files and headers with Jinja2 templates
  • VCS Versioning: Automatic version extraction from git tags

NOTE

The project isn't fully ready yet so please do not use it quite yet.

Installation

pip install build-cub

With uv:

uv add build-cub

Quick Start

1. Add to your build system

In your pyproject.toml:

[build-system]
requires = ["hatchling", "build-cub"]
build-backend = "hatchling.build"

[tool.hatch.build.hooks.custom]
path = "hatch_build.py"

2. Create the build hook

Create hatch_build.py in your project root:

from build_cub.plugins import BuildCubHook

class CustomBuildHook(BuildCubHook):
    PLUGIN_NAME = "custom"

3. Configure your build

Create bear_build.toml in your project root:

[general]
name = "my_package"
enabled = true

[defaults.settings]
extra_compile_args = ["-O3", "-ffast-math"]
extra_link_args = ["-O3"]

[cython]
enabled = true
targets = ["src/my_package/fast.pyx"]

[cython.compiler_directives]
language_level = "3"
boundscheck = false
wraparound = false

4. Build your package

uv build
# or
pip wheel .

Configuration Reference

General Settings

[general]
name = "my_package"        # Package name
enabled = true             # Master switch for all compilation
debug_symbols = false      # Include debug symbols (-g flag)

Compiler Defaults

[defaults.settings]
extra_compile_args = ["-O3", "-std=c++20"]
extra_link_args = ["-O3"]
extra_compile_args_windows = ["/O2", "/std:c++20"]
extra_link_args_windows = ["/IGNORE:4099"]
include_dirs = []
library_dirs = []
libraries = []

[defaults.output_files]
lib_files = [".so", ".pyd"]

Cython Backend

[cython]
enabled = true
annotate = false           # Generate HTML annotation files
quiet = true               # Suppress compiler output
cleanup = true             # Remove intermediate .c/.cpp files
targets = ["src/pkg/module.pyx"]

[cython.settings]
# Override defaults for this backend only
extra_compile_args = ["-O2"]

[cython.compiler_directives]
language_level = "3"
embedsignature = true
boundscheck = false
wraparound = false
cdivision = true

PyBind11 Backend

[pybind11]
enabled = true
targets = [
    { name = "bindings", sources = ["src/pkg/_cpp/bindings.cpp"] }
]

Native C/C++ Backend

[native]
enabled = true
targets = [
    { name = "core", sources = ["src/pkg/_c/core.c", "src/pkg/_cpp/utils.cpp"] }
]

PyO3 Backend

[pyo3]
enabled = true
release = true             # Build in release mode (optimized)
quiet = false              # Show cargo build output
features = []              # Cargo features to enable

Gperf Preprocessing

[gperf]
enabled = true
binary = "/usr/bin/gperf"
language = "C++"

Version Templates

Generate version files from Jinja2 templates:

[versioning.variables]
database = { major = 2, minor = 0, patch = 0 }

[[versioning.templates]]
output = "src/my_package/_version.py"
content = '''
__version__ = "{{ version.major }}.{{ version.minor }}.{{ version.patch }}"
__db_version__ = "{{ database.major }}.{{ database.minor }}.{{ database.patch }}"
'''

[[versioning.templates]]
output = "src/my_package/_cpp/version.hpp"
content = '''
#pragma once
constexpr int VERSION_MAJOR = {{ version.major }};
constexpr int DB_VERSION_MAJOR = {{ database.major }};
'''

The version variable is automatically injected from VCS (git tags).

Requirements

  • Python 3.12+
  • Hatchling build backend
  • Backend-specific requirements:
    • Cython backend: cython
    • PyBind11 backend: pybind11
    • PyO3 backend: Rust toolchain (rustup + cargo)
    • Gperf backend: gperf binary installed

Metadata

Release files for build-cub 0.0.46

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for build-cub 0.0.46
File Interpreter ABI Platform Actions
build_cub-0.0.46-py3-none-any.whl Python 3 none any Details for build_cub-0.0.46-py3-none-any.whl

Release files / build_cub-0.0.46-py3-none-any.whl

Download URL build_cub-0.0.46-py3-none-any.whl
Size 79.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae9ead11e97fc1bbd443eb54f02ef96888434d0ed70490cea3200486a012d151
BLAKE2b-256 checksum
How to use checksums
2586927fe24e1e34c26d04245650050c0ffd4b63e8ea3d4cbeb77f78bbd11209
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for build-cub 0.0.46

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 1 file in this release has been uploaded with provenance metadata.

Attestation for build_cub-0.0.46-py3-none-any.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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