Skip to main content

C/C++ header parsing toolkit with IR, libclang backend, and CFFI writer

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

clangir

CI Docs PyPI Python

C Intermediate Representation - a Python library for parsing C/C++ headers.

Full documentation: https://axiomantic.github.io/clangir/

Provides an IR data model for parsed C/C++ declarations, a libclang parser backend, and a CFFI cdef writer.

Installation

Requires Python 3.10+.

pip install clangir

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

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

Usage

from clangir.backends import get_backend
from clangir.writers.cffi import header_to_cffi

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

This produces CFFI-compatible C declarations that can be passed to ffi.cdef():

struct MyStruct {
    int field;
    ...
};
void my_function(int arg);

Development

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

License

This project is licensed under the MIT License.

The vendored clang Python bindings in clangir/_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

clangir-0.3.1.tar.gz (217.9 kB view details)

Uploaded Source

Built Distribution

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

clangir-0.3.1-py3-none-any.whl (183.2 kB view details)

Uploaded Python 3

File details

Details for the file clangir-0.3.1.tar.gz.

File metadata

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

File hashes

Hashes for clangir-0.3.1.tar.gz
Algorithm Hash digest
SHA256 227c4a107fc82d68c88ca8ae2af71c0406e36bcbb5abec98207ffe1de5378a57
MD5 5236225680f5fe173e74db233f648ad3
BLAKE2b-256 954bd37ca8c94403e7f9d1cf9b3a3d630ac04a019702e9f2b92b785c1cf3ad2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for clangir-0.3.1.tar.gz:

Publisher: release.yml on axiomantic/clangir

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

File details

Details for the file clangir-0.3.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for clangir-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab59ebf7aca9142be024e58ab3911f2e0a6b44de41d498412df750cb5ddac32f
MD5 564802f0bb058b0dca11a95ccecd5e1d
BLAKE2b-256 792c4bcc7554d91904defdbe9dffa43085fd49b9a4dfdccea175abd0d2601b37

See more details on using hashes here.

Provenance

The following attestation bundles were made for clangir-0.3.1-py3-none-any.whl:

Publisher: release.yml on axiomantic/clangir

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