Skip to main content

C/C++ header analysis toolkit with pluggable backends and writers for ctypes, Cython, CFFI, LuaJIT FFI, and more

Project description

headerkit

CI Docs PyPI Python

A general-purpose C/C++ header analysis toolkit with a pluggable architecture. Parse once with libclang, output to any format through 7 built-in writers.

headerkit carries the torch for ctypesgen2 as a ctypes binding generator and serves as the new engine behind autopxd2 for Cython .pxd generation.

Full documentation: axiomantic.github.io/headerkit

Architecture

headerkit separates parsing from output generation. A parser backend (currently libclang) produces a language-neutral IR (intermediate representation), and any number of writers consume that IR to generate output. Add a backend, and all writers benefit. Add a writer, and all backends feed it.

C/C++ headers --> [libclang backend] --> IR --> [writer] --> output

Writers

Writer Output Description
cffi CFFI cdef strings Declarations for ffibuilder.cdef()
ctypes Python modules Complete ctypes binding modules (successor to ctypesgen2)
cython .pxd files Cython declaration files with C++ support (ported from autopxd2)
diff JSON or Markdown API compatibility reports between header versions
json JSON Full IR serialization for inspection and tooling
lua LuaJIT FFI bindings ffi.cdef() declarations for LuaJIT
prompt Compact text Token-optimized IR output for LLM context windows

Installation

Requires Python 3.10+. Zero runtime dependencies.

pip install headerkit

System Requirements

libclang shared library must be installed:

  • macOS: brew install llvm or Xcode Command Line Tools
  • Ubuntu: sudo apt install libclang-dev
  • Fedora: sudo dnf install clang-devel
  • Windows: Download the LLVM installer or winget install LLVM.LLVM

Or use the bundled installer:

headerkit-install-libclang

Supports LLVM 18, 19, 20, and 21. The appropriate version is detected automatically.

Usage

Parse a header and generate output with any writer:

from headerkit.backends import get_backend
from headerkit.writers import get_writer

backend = get_backend("libclang")
header = backend.parse('#include "mylib.h"', "wrapper.h", include_dirs=["/path/to/include"])

# CFFI bindings
cffi_writer = get_writer("cffi")
print(cffi_writer.write(header))

# ctypes bindings
ctypes_writer = get_writer("ctypes")
print(ctypes_writer.write(header))

# Cython .pxd
cython_writer = get_writer("cython")
print(cython_writer.write(header))

# JSON for tooling
json_writer = get_writer("json")
print(json_writer.write(header))

List available writers:

from headerkit.writers import list_writers
print(list_writers())  # ['cffi', 'ctypes', 'cython', 'diff', 'json', 'lua', 'prompt']

Development

git clone https://github.com/axiomantic/headerkit.git
cd headerkit
pip install -e '.[dev]'
pytest

License

This project is licensed under the MIT License.

The vendored clang Python bindings in headerkit/_clang/v*/ are from the LLVM Project and are licensed under the Apache License v2.0 with LLVM Exceptions.

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

headerkit-0.5.0.tar.gz (327.0 kB view details)

Uploaded Source

Built Distribution

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

headerkit-0.5.0-py3-none-any.whl (216.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: headerkit-0.5.0.tar.gz
  • Upload date:
  • Size: 327.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for headerkit-0.5.0.tar.gz
Algorithm Hash digest
SHA256 0e8af4da3570b18a2b95435b0cb44103ec29ea2e9d8bc33643bfebcacc26a26c
MD5 a77f905b95a1c8f27cbadecbc566a506
BLAKE2b-256 71ff099c650f5887203f099d3fc4b1e753f216741afe27ac47abf6a371937ca8

See more details on using hashes here.

Provenance

The following attestation bundles were made for headerkit-0.5.0.tar.gz:

Publisher: release.yml on axiomantic/headerkit

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

File details

Details for the file headerkit-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: headerkit-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 216.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for headerkit-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a32b7f0826ed62e3ed78d2403dcaf08029a96004967024fbdfc5fcc305325135
MD5 f3d2556895a921a55183fc49f36c9fb1
BLAKE2b-256 c9f5eb61f0697f9c195c782ab7ea490aab13410c1ca673b3618fcdcaa9e6b03d

See more details on using hashes here.

Provenance

The following attestation bundles were made for headerkit-0.5.0-py3-none-any.whl:

Publisher: release.yml on axiomantic/headerkit

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