Fast, open-source static analysis CLI that finds bugs and enforces coding standards using code-like patterns instead of regex or ASTs.
eliben/pycparser
A complete C99/C11 parser written in pure Python, producing an AST from C source code with no external dependencies.
- Stars
- 3,577
- Forks
- 657
- Open issues
- 19
- Last commit
- 18 hours ago
What is it?
pycparser parses C source code and builds an abstract syntax tree (AST) that Python programs can traverse and modify. It follows the C grammar from Annex A of the C99 standard and aims to cover C11, with C23 support available through a dialect setting. It is implemented in pure Python with no dependencies beyond the interpreter, so it installs easily with pip.
Because C code usually needs preprocessing first, pycparser can call an external preprocessor such as cpp, gcc -E, or clang -E, either through its parse_file function or by passing already preprocessed code. It also ships minimal fake standard library headers in utils/fake_libc_include to speed up parsing of files that include system headers.
The project is widely used as a component in other tools, most notably the cffi library, which relies on it to read C function and type declarations.
Key features
- 01Parses C99 and C11 source, with C23 available via a dialect option.
- 02Written in pure Python with no external dependencies.
- 03Produces an AST whose node types are documented in _c_ast.cfg.
- 04Works with an external preprocessor such as cpp, gcc -E, or clang -E.
- 05Includes minimal fake libc headers for faster parsing of code with standard includes.
Use cases
- Building a static code checker or linter for C code.
- Writing source-to-source transformations or obfuscators for C.
- Adding custom extensions to the C language through AST rewriting.
- Generating FFI bindings by parsing C header declarations, as cffi does.
Quick start
- 1
Install pycparser with pip
pip install pycparser - 2
Browse the examples directory for usage samples
Things to know
- Most realistic C code needs an external C preprocessor (cpp, gcc -E or clang -E) before parsing.
- The README does not say which standard headers are bundled in the pip package; the fake libc headers are not included in it.
Topics
FAQ
- What is pycparser?
- A complete C99/C11 parser written in pure Python, producing an AST from C source code with no external dependencies. pycparser parses C source code and builds an abstract syntax tree (AST) that Python programs can traverse and modify. It follows the C grammar from Annex A of the C99 standard and aims to cover C11, with C23 support available through a dialect setting. It is implemented in pure Python with no dependencies beyond the interpreter, so it installs easily with pip.
- Is pycparser free to use? What license does it have?
- pycparser is open source under the Other license. Check the license terms before using it in commercial products.
- Is pycparser still maintained?
- Actively maintained. The last commit to pycparser was on Oct 19, 2026.
- What can I use pycparser for?
- Building a static code checker or linter for C code. Writing source-to-source transformations or obfuscators for C. Adding custom extensions to the C language through AST rewriting. Generating FFI bindings by parsing C header declarations, as cffi does.
- How do I install pycparser?
- Install pycparser with pip: pip install pycparser Browse the examples directory for usage samples
- Where can I get pycparser?
- The source code and installation instructions are on GitHub: https://github.com/eliben/pycparser
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A beta Python utility for creating bootable USB drives from ISO images on Linux, inspired by Rufus on Windows.
A 17-lesson Python tutorial that builds a Claude Code-like agent harness from scratch, starting with a single loop and bash.
A toolkit that generates agent-native command-line interfaces for existing software, plus a CLI-Hub registry for installing ready-made ones.
Open-source Python SDK and service for detecting and anonymizing PII in text, images and structured data.
A tiny C++ library that sends small amounts of data between devices using sound, usable from Python, JavaScript, and microcontrollers.