Skip to main content

Showcase use and packaging of a C++ extension module alongside pure Python code

Project description

hello-c-extension

PyPI version License: MIT Python versions

A minimal, working example of how to package a Python project that combines pure-Python code with a C++ extension module — using modern (PEP 517 / 621 / 639) pyproject.toml-based build configuration and the uv + task workflow.

The package cmod exposes:

Name Kind Defined in
cmod.CONSTANT package-level Python constant src/cmod/__init__.py
cmod.pymod pure-Python submodule src/cmod/pymod.py
cmod._cmod compiled C++ extension submodule src/cmod/_cmodule.cc

Install

python -m pip install hello-c-extension

Use

>>> from cmod import CONSTANT, pymod, _cmod
>>> CONSTANT
10
>>> pymod.hello()
Hello from Python!
>>> _cmod.foo()
5

Project layout

hello-c-extension/
├── pyproject.toml            # PEP 621 metadata + ext-modules + tool config
├── uv.lock                   # reproducible dependency lock (committed)
├── Taskfile.yml              # command shortcuts (task ...)
├── .pre-commit-config.yaml   # hooks runnable via prek
├── CHANGELOG.md              # Keep a Changelog
├── CLAUDE.md                 # guidance for AI-assisted development
├── .editorconfig
├── .github/
│   ├── dependabot.yml        # weekly uv + github-actions updates
│   └── workflows/
│       ├── ci.yml            # lint + matrix test + build
│       └── publish.yml       # tag-triggered OIDC publish + Sigstore + release
├── src/cmod/
│   ├── __init__.py
│   ├── pymod.py              # pure-Python submodule
│   ├── _cmodule.cc           # C++ source for the compiled submodule
│   ├── _cmod.pyi             # type stubs for the compiled submodule
│   └── py.typed              # PEP 561 marker (shipped in wheel)
└── tests/
    └── test_cext.py          # pytest (unittest-style)

Development

Requires Python 3.10 - 3.14, uv, task, and a C++-capable compiler.

task sync       # create .venv and install project + dev deps
task test       # pytest + coverage (>=75% enforced)
task lint       # ruff check + ruff format --check + ty check
task format     # auto-format and apply safe fixes
task build      # uv build -> sdist + wheel into dist/
task hooks      # run all pre-commit hooks via `uvx prek run --all-files`
task check      # full verification: lint + tests + build

Pre-commit hooks

Run via prek (drop-in pre-commit replacement; shares .pre-commit-config.yaml):

uvx prek install      # install git hook
uvx prek run --all-files

Configured hooks: ruff, ruff-format, ty, markdownlint-cli2, and basic hygiene (end-of-file fixer, trailing whitespace, check-ast, check-merge-conflict, debug-statements, mixed-line-ending).

Build backend

This project uses setuptools as the PEP 517 build backend. Astral's uv_build backend is pure-Python only and cannot compile C/C++ extensions, so setuptools with declarative [[tool.setuptools.ext-modules]] is used instead. uv still drives the developer workflow (env, deps, build, run).

Releasing

Releases are tag-driven. Pushing a v* tag triggers publish.yml:

  1. Build sdist + wheel with uv build.
  2. Export an SBOM (locked requirements) via uv export.
  3. Publish to PyPI using Trusted Publishing (OIDC) — no API token stored in the repo.
  4. Sign the distributions with Sigstore.
  5. Create a GitHub Release containing the signed distributions and SBOM.

All GitHub Actions are pinned to full commit SHAs. Jobs run with least-privilege permissions: scopes. The pypi GitHub environment can be configured with protection rules (required reviewers, wait timers) for an extra manual gate on releases.

License

MIT - see LICENSE.

Project details


Download files

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

Source Distribution

hello_c_extension-0.6.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distributions

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

hello_c_extension-0.6.0-cp314-cp314-win_amd64.whl (10.6 kB view details)

Uploaded CPython 3.14Windows x86-64

hello_c_extension-0.6.0-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (21.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

hello_c_extension-0.6.0-cp314-cp314-macosx_10_15_universal2.whl (8.5 kB view details)

Uploaded CPython 3.14macOS 10.15+ universal2 (ARM64, x86-64)

hello_c_extension-0.6.0-cp313-cp313-win_amd64.whl (10.4 kB view details)

Uploaded CPython 3.13Windows x86-64

hello_c_extension-0.6.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (21.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

hello_c_extension-0.6.0-cp313-cp313-macosx_10_13_universal2.whl (8.4 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

hello_c_extension-0.6.0-cp312-cp312-win_amd64.whl (10.4 kB view details)

Uploaded CPython 3.12Windows x86-64

hello_c_extension-0.6.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (18.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

hello_c_extension-0.6.0-cp312-cp312-macosx_10_13_universal2.whl (8.4 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

hello_c_extension-0.6.0-cp311-cp311-win_amd64.whl (10.4 kB view details)

Uploaded CPython 3.11Windows x86-64

hello_c_extension-0.6.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (18.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

hello_c_extension-0.6.0-cp311-cp311-macosx_10_9_universal2.whl (8.4 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

hello_c_extension-0.6.0-cp310-cp310-win_amd64.whl (10.4 kB view details)

Uploaded CPython 3.10Windows x86-64

hello_c_extension-0.6.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (18.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

hello_c_extension-0.6.0-cp310-cp310-macosx_10_9_universal2.whl (8.4 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file hello_c_extension-0.6.0.tar.gz.

File metadata

  • Download URL: hello_c_extension-0.6.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for hello_c_extension-0.6.0.tar.gz
Algorithm Hash digest
SHA256 050bd9959cad440b7cc6359f7a6356c26d5ac378c8651c1aa337b1f52873b2ec
MD5 7f9c56a2d50ffc0b4c55b4327aae6d2a
BLAKE2b-256 a6af92d293ac3a031863ed60d42844df0a2bf03e992cd673cc11b633d10d64cf

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 79620e79d975dbb89ebc371270978c5209f3ae9cafb159ed6c7d905ba6698257
MD5 ef5600267832c77a211131f0aa93bea6
BLAKE2b-256 6ce2845a61130bd2a17a9afd7bb8ac415660e9781310ac323475df3c5a96757e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp314-cp314-win_amd64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 9d3328876b56e20fada6a7b250d226022e2da8e698aa0bd7f7c62b9022c4f51a
MD5 edacfb8ed2eff8cf82b37100b696db5a
BLAKE2b-256 1a3fd7664aa28e3275452f014d58eca30b85373c486f86038eae126674b39104

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp314-cp314-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 2724d47525b7b4176927b51c8032b253a77a2e602d73f23162960c2a5f35f724
MD5 ccc82091230a0e380bb1f2ef7b1fdc1c
BLAKE2b-256 7220c82e282adb468b7ead642db47f8c7f38684a9f6ec7a5d0c36b1e7f9a13a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp314-cp314-macosx_10_15_universal2.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 062988151f39d518bbd1fb850cf290f8609c0369ea3f5ee08800077cc84139b1
MD5 582ce5295b813c4fa16b27d1be8e0e0d
BLAKE2b-256 ecd7a1b04ec1930f63f50f634948265f7ba16daf53d9aef98c58821054a68d86

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 319af797a3b1ae758cf635df7629f85a674326dcc93379eb378f141f28bf9fb1
MD5 e0f4785e4c9d6ab61c2318de51392709
BLAKE2b-256 6de450dd158854e4d0ba79df4c8a3c34ac4cf8c6c0b592b60ff33757c93d6a32

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 d4b920441ef7202df212bd1854083422263817f7854c57ff9bbcf70879f3a4ec
MD5 d55be319502e286e7eabb039f070fe47
BLAKE2b-256 1d5162b1173f33af78c455ad47d1c9ab3f9b4044cde5d62c3ff7b2d16c3e239c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp313-cp313-macosx_10_13_universal2.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fed19934baad4d3ea9790d04d799e4789fa0c211a4dfe31e7647a49e008cfa6a
MD5 7ab292715c31fe1aa6bd8ba528e76005
BLAKE2b-256 db18e17b4169b927f96b4f2282afa6df1d214dd4fe09a60cdf748fad412b1b0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 f95f9aa3c463583adcb0208fee2f0d389e4909c42353556fe019352cd066e9db
MD5 d9c1c57a548fe3efd90a53bf44889018
BLAKE2b-256 016ff2198dce4516fe690285d1a8e3fbd0d28f583fe30ee24c3955883d2f4b67

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 ff23887a5f8ba433275d6f08639dd0c25bf84c6d2756f1b7601c9b88fb5f9ec1
MD5 142439569e2da9b6a0ec92f5971bb0a7
BLAKE2b-256 d4dc483c41b47c3ec3ab264fcd30660f6fadaf72954a74a0177de480177bf23d

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 505fec573446e671f3077c1afec2cf8f08aced851565ca200de3ee1acfe1245b
MD5 fd5e28cfef5492770bf411c4e6748e0e
BLAKE2b-256 58bbee9aede9aee4d735492a7a306e5e42c3539f4c1c695fab38f16e33f9febd

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp311-cp311-win_amd64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 042ec61a74faa9fb2981f3caedc6b73b812321cffe827f10a7db83c574c12d06
MD5 cc1954d73fe33e1de9d2b24d8c79b630
BLAKE2b-256 71b021663588532bc6aa6f581d5f4a0910a2fbd31c48b0e05c5f00fea53045f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f661e585e8c02779184edfd584cde654d5edc8372d8cb824df7140447fe79042
MD5 77e8fccd6aa9af8a2e19844ba94f5f11
BLAKE2b-256 62980c8f08bb4bab27aafc9235e9319d333b580f1d10f86af3335d770ff5c7f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e4c603234f04cf61cca110f355300912d32981c45e2138be346b8299bd397179
MD5 c7d71183f9654d89049e344b2b5eacaa
BLAKE2b-256 d578b44e3a6789ab876f8016788a02fff5f2337d62ae72da1da7a034f7f81e74

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp310-cp310-win_amd64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 59bfbcbbfaf87f0a3e05fbedfe587085f6b473c8b1220b575b86831edfb69d32
MD5 649b1e1c41838556d3fa21fb363dcc8d
BLAKE2b-256 ecf6c4db18c34d1f58981f1bf721f18c4d6660f7dadafddeee32525a5b01926f

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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

File details

Details for the file hello_c_extension-0.6.0-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for hello_c_extension-0.6.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ede78158854a75848eab725bcb7f2ab5ab4ec5a253a9d8f6e31678cb17e5e9d5
MD5 d48a98befd3acc049db7f1278dfc8adc
BLAKE2b-256 00a464ac2201c7180896c4799106f5989849221756d2b5e386cca4151dc4ef5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for hello_c_extension-0.6.0-cp310-cp310-macosx_10_9_universal2.whl:

Publisher: publish.yml on bsolomon1124/hello-c-extension

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