pycparser
C parser in Python
Decision gist · record as of 2026-08-14
Yes. pycparser is a mature, actively maintained library (top 20 PyPI package) with no external dependencies, permissive licensing, and proven real-world use in projects like cffi. Install it if you need to parse C code programmatically in Python. The main gotcha is the requirement for a C preprocessor in your environment, which is documented and straightforward to set up.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires a C preprocessor (cpp, gcc -E, or clang -E) in your PATH or explicitly provided to handle #include and #define directives in real C code.
- Installation is straightforward with no external dependencies beyond Python itself.
- The package is actively maintained with recent commits and supports modern Python versions from 3.10 onwards.
License · maintenance · safety
BSD-3-Clause (permissive) — Licensed under BSD-3-Clause (permissive), allowing use in both open-source and proprietary projects with minimal restrictions.
last release 2026-01-21 (205 days) · last repo commit 2026-07-29 · 3,559 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 1,107,200,067 downloads/mo, #20 on PyPI
Alternatives
Verify before relying
pip install pycparser
from pycparser import parse_file
ast = parse_file('example.c', use_cpp=True)- Whether fake_libc_include headers are available in the pip-installed package or only in the repository source.
- Performance characteristics when parsing large C files with the provided fake headers.
What it is and what it does
pycparser is a pure-Python parser for the C language that converts C source code into an abstract syntax tree (AST) suitable for programmatic analysis and manipulation. It aims to support the full C99 standard with some C11 features, following the grammar from the C99 standard closely. The parser is designed to be easily integrated into applications that need to understand C code structure without external compilation dependencies.
The package requires preprocessed C code as input, meaning your code must first pass through a C preprocessor (cpp, gcc -E, or clang -E) to handle directives like #include and #define. pycparser provides a convenience function to automate this if a preprocessor is available in your PATH. It includes minimal fake standard library headers to allow parsing of typical C code that references stdio.h and similar headers, though these are not included in the pip package.
Use it for
- Building C code analysis tools, static checkers, or obfuscators that need to understand C syntax and structure.
- Creating front-ends for specialized C compilers or code generators that transform C into other languages.
- Integrating C function and type declarations into Python via FFI libraries like cffi.
- Automatic discovery and extraction of C code patterns for testing or documentation purposes.
- Extending or modifying C language semantics by parsing and transforming the AST before code generation.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
pycparser is a mature, actively maintained library (top 20 PyPI package) with no external dependencies, permissive licensing, and proven real-world use in projects like cffi. Install it if you need to parse C code programmatically in Python. The main gotcha is the requirement for a C preprocessor in your environment, which is documented and straightforward to set up.
Install
pycparser on PyPI
Before you install
Installation is straightforward with no external dependencies beyond Python itself. The package is actively maintained with recent commits and supports modern Python versions from 3.10 onwards.
Requires a C preprocessor (cpp, gcc -E, or clang -E) in your PATH or explicitly provided to handle #include and #define directives in real C code.
License in practice
Licensed under BSD-3-Clause (permissive), allowing use in both open-source and proprietary projects with minimal restrictions.
Quickstart
pip install pycparser
from pycparser import parse_file
ast = parse_file('example.c', use_cpp=True)
Verify before relying
- Whether fake_libc_include headers are available in the pip-installed package or only in the repository source.
- Performance characteristics when parsing large C files with the provided fake headers.
Package facts
| License | BSD-3-Clause permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 205 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,107,200,067 / month, #20 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14 |
Evidence: pycparser-3.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “C preprocessor integration”
- pycparserpycparser is a C language parser written in pure Python that parses C…
- pcppA pure Python implementation of a C99 preprocessor that can…
- fyppFypp is a Python-powered preprocessor for Fortran that adds…
Give your agent the search over MCP, or paste the wish link into any chat.
Similar packages
Parses C++ header files into Python data structures, extracting class definitions, functions, and modern C++ constructs without requiring a full AST or compiler validation.
Provides a C language grammar for tree-sitter, enabling incremental parsing and syntax tree analysis of C code.
A pure Python implementation of a C99 preprocessor that can preprocess C/C++ header files and source code, available both as a Python module and command-line tool.
However, the 2021 release date and aging maintenance status mean it may not track the latest C standards or receive active bug fixes—suitable for established…
Provides a Python grammar for tree-sitter, enabling incremental parsing and syntax tree analysis of Python code.
However, the last release was 337 days ago—verify that the grammar version meets your Python syntax requirements before committing to it in production.
phply is a lexer and parser for PHP source code that generates abstract syntax trees, enabling PHP code analysis and conversion to other formats like JSON or Jinja2 templates.
Provides a Ruby language grammar for tree-sitter, enabling incremental parsing and abstract syntax tree generation for Ruby code.
See also Nuitka · luaparser · ctypesgen · tree-sitter-cpp