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.6.0.tar.gz (329.8 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.6.0-py3-none-any.whl (217.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for headerkit-0.6.0.tar.gz
Algorithm Hash digest
SHA256 ae0ea4f26689844a092e5355b939065be06a70c5c2c181618be441f6b66f2306
MD5 4106ed29c1d2ab41c7a721bceb2e8ebb
BLAKE2b-256 927df66b4bd36e1bfa66008778a0e9955080acb51a24c091edb86b329245e52d

See more details on using hashes here.

Provenance

The following attestation bundles were made for headerkit-0.6.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.6.0-py3-none-any.whl.

File metadata

  • Download URL: headerkit-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 217.0 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.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18ea6d80e3cda80a2ccf9822f187d0648e5f3cf8d01ccb776d84dfcfd0c077b3
MD5 4dda4be6edb8bdc7cc1cbf63deb0080e
BLAKE2b-256 37012356c8d763be4710cdbb525210456e1ce749183cbf085cf030afe7c94e92

See more details on using hashes here.

Provenance

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