Skip to main content

Clang Python Bindings, mirrored from the official LLVM repo: https://github.com/llvm/llvm-project/tree/main/clang/bindings/python.

Reason this release was yanked:

Old versioning schema is unsupported

Project description

libclang-ng

PyPI Python Downloads License

Arch: x64 Arch: aarch64

Linux x64 Linux Arm64 MacOS x64 MacOS Arm64 Windows x64 Windows Arm64

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 of libclang. The clang package on PyPI is a separate project and does not bundle a prebuilt shared library.

Installation

Install using pip:

pip install libclang-ng==19.1.7

Install using uv:

uv pip install libclang-ng==19.1.7

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 — there are no external runtime dependencies beyond the standard system libraries (glibc on Linux, system frameworks on macOS, MSVC runtime on Windows).

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

libclang_ng-19.1.7-py3-none-win_arm64.whl (18.4 MB view details)

Uploaded Python 3Windows ARM64

libclang_ng-19.1.7-py3-none-win_amd64.whl (20.9 MB view details)

Uploaded Python 3Windows x86-64

libclang_ng-19.1.7-py3-none-manylinux_2_28_x86_64.whl (26.4 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

libclang_ng-19.1.7-py3-none-manylinux_2_28_aarch64.whl (24.5 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

libclang_ng-19.1.7-py3-none-macosx_11_0_arm64.whl (27.2 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

libclang_ng-19.1.7-py3-none-macosx_10_9_x86_64.whl (28.1 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

File details

Details for the file libclang_ng-19.1.7-py3-none-win_arm64.whl.

File metadata

  • Download URL: libclang_ng-19.1.7-py3-none-win_arm64.whl
  • Upload date:
  • Size: 18.4 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for libclang_ng-19.1.7-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 dfb1759d0ac91dfc3b892b24bc3deb6a0b25cdbd2fb8b15da0806fab83569586
MD5 23fa65ec9d48beb4a98fa37f10c8271b
BLAKE2b-256 ac08259ea1049831c050b9914f3acd7678227f3828046c7aa63d9d0a23e2d7a4

See more details on using hashes here.

File details

Details for the file libclang_ng-19.1.7-py3-none-win_amd64.whl.

File metadata

  • Download URL: libclang_ng-19.1.7-py3-none-win_amd64.whl
  • Upload date:
  • Size: 20.9 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for libclang_ng-19.1.7-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 43de205805000f0eea30a6e933b9b3912ab50291fb1ddabf6f0f436103c6ab22
MD5 fe2b740889a0b0a07e796d8f898bfb96
BLAKE2b-256 1dc9317678d173f01503dd1b5b262c512ab300fcd3d9d9e7b3a475bfd5408eed

See more details on using hashes here.

File details

Details for the file libclang_ng-19.1.7-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libclang_ng-19.1.7-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a44e6a6385f00e28fc676af54f9ee7e3f0a708590af1925818b1f100e07452b5
MD5 6ef5c48d378a887e2c41213e5201b182
BLAKE2b-256 0422d3a06a0a0dee44d932b97bedb0b717a26e398d766b823462f292ca6146d0

See more details on using hashes here.

File details

Details for the file libclang_ng-19.1.7-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libclang_ng-19.1.7-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 462c192710d4f57690f9b56a5afab7fbf0b8e6a491ee7ee1b14c0d3790f9c022
MD5 16cef9b078dd32d6988ce4b4fa24fe1c
BLAKE2b-256 274e4290424a6d83fb0cffb78162cd2ac5cef58cb1230f30e322ea355ae811e0

See more details on using hashes here.

File details

Details for the file libclang_ng-19.1.7-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libclang_ng-19.1.7-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b683c82178034c6a6bc3720eb6f36819b2cf07241bde918f4c738177a05bddf6
MD5 d8bf71bb9122a39c6804d4edcc40b988
BLAKE2b-256 ae8ee89db9382e582517b4866948c97bc3123c626c9cb167ced1545a488cdb7f

See more details on using hashes here.

File details

Details for the file libclang_ng-19.1.7-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for libclang_ng-19.1.7-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dd8eb51132c49257a930b5806a3e1d9e7a7d6d220d4d6d6ac2e212af2e2f4af4
MD5 c02e1caae434d2476b607bf00a3badd9
BLAKE2b-256 38596265cc2d8affb6bce06f9cdeccf9bcfd7359f9366b5da08030ebff078a21

See more details on using hashes here.

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