libclang-ng
libclang-ng packages the official Clang Python Bindings (clang.cindex) from the LLVM project and bundles a statically-linked libclang shared library for each supported platform. The result is a zero-configuration pip install that gives you a working Clang Python API without installing the LLVM toolchain.
Note: This package is named
libclang-ng, and it's the natural evolution oflibclang. Theclangpackage on PyPI is a separate project and does not bundle a prebuilt shared library.
Installation
Install using pip:
pip install libclang-ng==20.1.8.1
Install using uv:
uv pip install libclang-ng==20.1.8.1
Best way to specify pinning is to allow for patch updates on the same clang version:
pip install "libclang-ng>=20.1.8.0,<21.0.0.0" --upgrade
Requirements
- Python 3.12 or later
Platform Support
| Platform | Architecture | Minimum OS |
|---|---|---|
| Linux | x86_64 | glibc 2.28+ (manylinux_2_28) |
| Linux | aarch64 | glibc 2.28+ (manylinux_2_28) |
| macOS | x86_64 | 10.9+ |
| macOS | arm64 | 11.0+ |
| Windows | x86_64 | — |
| Windows | arm64 | — |
All native libraries are statically linked and libcxx headers are bundled in the python package - there are no external runtime dependencies beyond the standard system libraries (glibc on Linux, system frameworks on macOS, MSVC runtime on Windows).
Clang Versions
Supported clang versions:
- 19.1.7 (https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.7)
- 20.1.8 (https://github.com/llvm/llvm-project/releases/tag/llvmorg-20.1.8)
- 21.1.8 (https://github.com/llvm/llvm-project/releases/tag/llvmorg-21.1.8)
- 22.1.4 (https://github.com/llvm/llvm-project/releases/tag/llvmorg-22.1.4)
Quick Start
Parse a file and walk the AST
from clang.cindex import Index, CursorKind
index = Index.create()
tu = index.parse("example.cpp", args=["-std=c++17"])
for cursor in tu.cursor.get_children():
if cursor.kind == CursorKind.FUNCTION_DECL:
print(f"Function: {cursor.spelling} at {cursor.location}")
for param in cursor.get_arguments():
print(f" param: {param.spelling} ({param.type.spelling})")
Parse from a string (in-memory)
from clang.cindex import Index
index = Index.create()
tu = index.parse(
"example.cpp",
unsaved_files=[("example.cpp", "int add(int a, int b) { return a + b; }")],
args=["-std=c++17"],
)
for cursor in tu.cursor.walk_preorder():
print(f"{cursor.kind.name}: {cursor.spelling}")
Collect diagnostics
from clang.cindex import Index, Diagnostic
index = Index.create()
tu = index.parse("example.cpp")
for diag in tu.diagnostics:
if diag.severity >= Diagnostic.Warning:
print(f"{diag.severity}: {diag.spelling} [{diag.location}]")
Type introspection
from clang.cindex import Index, CursorKind, TypeKind
index = Index.create()
tu = index.parse("example.cpp")
for cursor in tu.cursor.walk_preorder():
if cursor.kind == CursorKind.STRUCT_DECL:
t = cursor.type
print(f"struct {cursor.spelling}: size={t.get_size()} bytes")
for field in t.get_fields():
print(f" {field.spelling}: {field.type.spelling} offset={t.get_offset(field.spelling)} bits")
Use a compilation database
from clang.cindex import Index, CompilationDatabase
db = CompilationDatabase.from_directory("/path/to/build")
cmds = db.get_compile_commands("src/main.cpp")
index = Index.create()
for cmd in cmds:
tu = index.parse(cmd.filename, args=list(cmd.arguments)[1:])
API Overview
| Class | Purpose |
|---|---|
Index |
Entry point — creates and owns translation units |
TranslationUnit |
Represents a parsed source file; holds cursors and diagnostics |
Cursor |
A node in the AST (declaration, expression, statement, …) |
CursorKind |
Enumeration of all cursor node types |
Type |
Type information attached to a cursor |
TypeKind |
Enumeration of all type kinds |
Diagnostic |
A compiler warning or error with location and fix-it hints |
Token |
A lexical token (keyword, identifier, literal, …) |
SourceLocation |
File/line/column position in source |
SourceRange |
Start and end SourceLocation pair |
CompilationDatabase |
Reads compile_commands.json for project-wide parsing |
Full API documentation is generated from the module docstrings via Sphinx and is available at libclang-ng.readthedocs.io.
Configuration
By default the package locates libclang automatically from its bundled native/ directory. Override this when you want to use a system-installed or custom-built library:
Environment variable (before importing clang):
export LIBCLANG_LIBRARY_PATH=/usr/lib/llvm-19/lib
python your_script.py
Programmatic override (before any other clang import):
from clang.cindex import Config
Config.set_library_path("/usr/lib/llvm-19/lib")
# or point to a specific file:
# Config.set_library_file("/usr/lib/llvm-19/lib/libclang.so.19")
Development
The repository uses just as a task runner and uv as the Python package manager.
# Show the current LLVM version
just version
# Download LLVM source and update Python bindings
just download-llvm
# Full local build for macOS ARM64
just build-macos-arm64
CI / Release
Six GitHub Actions workflows build and publish a platform-specific wheel for each supported target. A release is triggered by pushing a version tag (v*), which causes each workflow to publish its wheel to PyPI.
License
This repository follows the license of the LLVM project: Apache-2.0 WITH LLVM-exception.
Metadata
Release files for libclang-ng 22.1.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| libclang_ng-22.1.4.2-py3-none-win_arm64.whl | Python 3 | none | Windows ARM64 | Details |
| libclang_ng-22.1.4.2-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| libclang_ng-22.1.4.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details |
| libclang_ng-22.1.4.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details |
| libclang_ng-22.1.4.2-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
| libclang_ng-22.1.4.2-py3-none-macosx_10_9_x86_64.whl | Python 3 | none | macOS 10.9+ x86-64 | Details |
Total release size: 176.8 MB
Release files / libclang_ng-22.1.4.2-py3-none-win_arm64.whl
| Download URL | libclang_ng-22.1.4.2-py3-none-win_arm64.whl |
|---|---|
| Size | 23.5 MB |
| Tags | Python 3 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
a76d7748d13fd47c0a604bfb752c5957171dbd715796daad8cd21b19fe5d8bcf
|
|
BLAKE2b-256 checksum How to use checksums |
b405de1e969a73ac5412b06bb72361c7763767c87be3d7eee12963afa155621f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / libclang_ng-22.1.4.2-py3-none-win_amd64.whl
| Download URL | libclang_ng-22.1.4.2-py3-none-win_amd64.whl |
|---|---|
| Size | 26.2 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
701b282404800d3fcf6d7d408cfd49ebae3e6a85dfb3f80a920deba67000dfa9
|
|
BLAKE2b-256 checksum How to use checksums |
bb2145df66fce5a3d9cf6b42131d1ecc1423bc1f70b8304e27c1ccb3edd40eae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / libclang_ng-22.1.4.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | libclang_ng-22.1.4.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 30.6 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
be0c485e086b1fd66fab5441df8507e863838f5b84f8cd327fe1eda2e93fb07a
|
|
BLAKE2b-256 checksum How to use checksums |
295b465354e121f7e4ab0023e464d1e5f09165460b0aefbd2fe6250a57620e6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / libclang_ng-22.1.4.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | libclang_ng-22.1.4.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 29.6 MB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
41ee012632993d0ea25c60da539d63ad858bc3261aaa706e5a4286bd2afc8372
|
|
BLAKE2b-256 checksum How to use checksums |
61c6ef0cae4dfb871eaae6811fb7873c64366ca7065ea1a590e858b267a96514
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / libclang_ng-22.1.4.2-py3-none-macosx_11_0_arm64.whl
| Download URL | libclang_ng-22.1.4.2-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 33.0 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
959cb4b15883b19e56704a68eceea015674c0830ecea423aa72e920225cf50ef
|
|
BLAKE2b-256 checksum How to use checksums |
e22b67a2cc4b12c0c7ce1e918e74f0f7fcd40f4509b6a1a1f3b18bd438098b6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / libclang_ng-22.1.4.2-py3-none-macosx_10_9_x86_64.whl
| Download URL | libclang_ng-22.1.4.2-py3-none-macosx_10_9_x86_64.whl |
|---|---|
| Size | 33.9 MB |
| Tags | Python 3 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
25c2a760f92e5a05f70b363e59607a97341a7a778c30b2987cea4bf186c56b57
|
|
BLAKE2b-256 checksum How to use checksums |
9d7993dd7866db6c0b37e1f93abfcc8e87879a46ecd5f52ca46673dd63ff605a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for libclang-ng 22.1.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.