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 Python package dependencies (nothing extra pulled from PyPI).

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.7.2.tar.gz (365.2 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.7.2-py3-none-any.whl (247.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for headerkit-0.7.2.tar.gz
Algorithm Hash digest
SHA256 2475b33fef792377960147899f13b8e24cab4e70800ad841590ebcfc44d961dd
MD5 bfca26a293986254dacd6d91c154f452
BLAKE2b-256 24d4d483bb2885883d837578ae3149ec4aa22d372e842fda062c5b0e90e63750

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: headerkit-0.7.2-py3-none-any.whl
  • Upload date:
  • Size: 247.6 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.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 241b1e3fd7a90c8e37de95ec62e3e3d7afcb7a33ec404596a7b17e03520989ab
MD5 48f2aa8acb7744dc88570c4c3110a3f3
BLAKE2b-256 4feb52ee463ee74aaa9e4e5f730566bce26378b002e5a9868894944b6d632528

See more details on using hashes here.

Provenance

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