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.1.tar.gz (364.9 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.1-py3-none-any.whl (247.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: headerkit-0.7.1.tar.gz
  • Upload date:
  • Size: 364.9 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.1.tar.gz
Algorithm Hash digest
SHA256 03a69d38b134558bd8636f44bb77fad0e8d868ae65d79aece6d7c8c69fd2dc6d
MD5 7cb40b6349e57d32902794b0b5cdc5f9
BLAKE2b-256 8bd825a34f1fcb0e811107af2499654935a10577ccf006665871c0ea93e9b422

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: headerkit-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 247.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2497f4d8c7474728e4698e552519e8cbe0233a9ec61cd88d8206a083c1854aba
MD5 d37fffa37d0c84f7b2604b23d98d75dc
BLAKE2b-256 f85396556db0c170c07a678f4eebe1cfca00a1b184bbefc449a8a713fb2aabc7

See more details on using hashes here.

Provenance

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