Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

pycparser

Read C code from Python scripts.

Languages, types and runtimesPYPI

GitHubWebsite

1. License

“Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met”

BSD 3-Clause allows commercial use; do not use the author's or contributors' names to promote your product.

github.com/eliben/pycparser/blob/main/LICENSE

From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error

What pycparser does

pycparser is a free Python library that reads C source code and turns it into a tree of parts a script can walk, like every function, type and parameter. It is for tools that check, document or change C code. Most people get it without asking, because CFFI uses it.

What people build with it

List the functions in a C header

Your script reads a library's header file and prints every function with its parameters, for docs or a wrapper.

Check C code for house rules

A small checker flags code that breaks your team's rules, such as a banned function or a missing return type, before review.

Find tests in C projects

Scan C test files for functions named test_* and build the list your test runner calls.

Generate bindings for other languages

Read a header once and write matching declarations for Python, Rust or JavaScript code that calls the same C library.

Rewrite C code automatically Idea

Change the tree, for example rename a function everywhere, and print it back as C source with the built-in code generator.

Teach how C declarations read Idea

Show students or teammates how a confusing declaration like a pointer to an array of functions breaks down, part by part.

pycparser popularity

73 / 100
Gid Score, #270 overall
282M
downloads a week, pypi
3,583
GitHub stars
39
agent projects use it
pycparser: downloads per weekPyPI, pycparser 280,374,411
pycparser: GitHub starseliben/pycparser 3,583

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How pycparser is used

  • pycparser is a dependency in 39 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (2.4% of the 1,623 Python ones), #10 of 70 in languages, types and runtimes.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,024; those are left out of every share on this page.
  • The most used alternative in our scan is Cython (4 projects).
  • Projects that use it most often also use CFFI (97.4%), Pydantic (94.9%), Click (89.7%).

By coding agent

26 projects, 0.9%
21 projects, 0.6%
11 projects, 0.5%

Often used with

In 97.4% of its projects
In 94.9% of its projects
In 89.7% of its projects
In 89.7% of its projects
In 87.2% of its projects

More about pycparser

More in Languages, types and runtimes

Alternatives

pycparser This page

BSD-3-ClauseGid 73282M/wk

libclang

Pick libclang when you need the real Clang compiler's view of the code, including C++, and can install LLVM.

tree-sitter-c

Pick the Tree-sitter C grammar for editors and code search that must cope with half-written code and skip the preprocessor.

PLY

Pick PLY when you want to build a parser for your own small language rather than read C.

Cython

Compiles Python to C for performance-critical code and C extensions.

Apache-2.0Gid 6923.8M/wk

Compare pycparser with another tool

Get started

Tell your AI assistant

“Use pycparser (pin pycparser==3.12, Python 3.11+) to parse this C header with parse_file(path, use_cpp=True) and a c_ast.NodeVisitor, then list every function with its parameters; run the C preprocessor first, never feed raw files with include lines or comments.”

  1. Install it with pip into your project's environment; it has no other packages of its own.

    > pip install pycparser

    From github.com/eliben/pycparser/blob/main/README.rst

  2. Parse a short piece of C directly, or a real file through the C preprocessor with parse_file(use_cpp=True).

    from pycparser import CParser, parse_file
    
    ast = parse_file(
        "example.c",
        use_cpp=True,
        cpp_args=["-std=c23"],
        parser=CParser(dialect="c23"),
    )
    

    From github.com/eliben/pycparser/blob/main/README.rst

  3. Walk the tree with a NodeVisitor subclass and pick the parts you need.

    From github.com/eliben/pycparser/blob/main/README.rst

Mistakes to avoid

CParser().parse(open("file.c").read()) on a real file with #include, #define or comments
parse_file("file.c", use_cpp=True), or run gcc -E / clang -E first and parse the output

In our run the raw header failed with "ParseError - :1:1: Directives not supported yet"; through cpp it parsed.

Preprocessing with the system's real headers (stdio.h and friends) and hitting errors on compiler extras
Point the preprocessor at the fake headers from the project's utils/fake_libc_include with -I

The real system headers are full of compiler extensions; the fake ones hold only what parsing needs.

Expecting pip install pycparser to bring utils/fake_libc_include
Fetch that folder from the project's source (a release archive) and keep it in your repository

The fake headers are not part of the pip package.

Parsing C23 code with bool or other new keywords using the default parser
CParser(dialect="c23") together with cpp_args=["-std=c23"]

C23 support is off by default because its new keywords clash with older code.

pip install pycparser==3.12 on Python 3.10
Use Python 3.11+ for 3.x, or let pip pick an older 2.x release on Python 3.10

pycparser 3.12 declares Python 3.11 as the minimum.

Questions

Why did I get pycparser without installing it?

CFFI uses pycparser to read C declarations, so installing CFFI (or a package built on it) brings it in.

Does it need anything else installed?

No other Python packages. For real files you also need a C preprocessor such as cpp, gcc -E or clang -E on your PATH.

Did version 3 change how I use it?

Version 3.00 rewrote the parser by hand and dropped the PLY dependency; the release notes say the same tree comes out.

Can it read C23 code?

Yes, when you create the parser with dialect="c23" and pass -std=c23 to the preprocessor yourself.

Can I use it in a commercial product?

Yes. The BSD 3-Clause license allows it if you keep the notice and do not use the author's name for promotion.