pcpp
A C99 preprocessor written in pure Python
What it is and what it does
pcpp is a C99 preprocessor written entirely in Python, designed to handle C and C++ preprocessing tasks at build or packaging time. It processes #include directives, macro definitions, and conditional compilation blocks, and can output either fully expanded code or partially preprocessed code with selective pass-through of certain directives. The package is useful for collapsing header-only C++ libraries into single files, preparing code for documentation tools like Doxygen, or integrating preprocessing into Python-based build pipelines.
The preprocessor passes a modified mcpp unit test suite and handles complex recursive macro expansions that conform to C99 standards. It offers both a Python API (by subclassing the Preprocessor class) and a command-line tool that mimics conventional C preprocessors. Partial preprocessing modes allow fine-grained control over which directives are executed versus passed through, making it flexible for different build scenarios.
Use it for:
- Collapse header-only C++ template libraries into single-file includes for easier distribution
- Preprocess C code before feeding it to documentation generators like Doxygen that have limited preprocessor capabilities
- Expand macros and resolve conditional compilation in C source files as part of a Python-based build system
- Benchmark and analyze header file complexity to identify optimization opportunities in build times
- Selectively expand nested includes while preserving system header references in generated output
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
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.
Yes, if you need C99 preprocessing in a Python environment. The package is stable and dependency-free, making it easy to integrate. 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 workflows but verify compatibility with your specific C/C++ code patterns first.
Install
pcpp on PyPI
pip
pip install pcppuv
uv add pcpppoetry
poetry add pcppInstalling pcpp
Before you install
Low install friction with no runtime dependencies. Package is in production/stable status but aging—last release was in 2021, though the repository remains active with recent commits.
License in practice
BSD license (permissive) means you can use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions.
Quickstart
pip install pcpp
from pcpp.preprocessor import Preprocessor
prep = Preprocessor()
prep.parse(open('input.h').read())
print(prep.write())
Verify before relying
- Whether Python 2 support (listed in classifiers) is actively maintained given the 2021 release date
- Current performance characteristics under modern Python versions compared to the stated 0.84x–2.62x range under PyPy
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 1,750 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 791,555/month — #5,046 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pcpp-1.30-py2.py3-none-any.whl
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
fyppFypp is a Python-powered preprocessor for…
permissive · top 15,000 on PyPI
pycparserpycparser is a C language parser written in…
permissive · top 100 on PyPI
cxxheaderparserParses C++ header files into Python data…
permissive · top 15,000 on PyPI
barectfbarectf generates ANSI C tracers that output…
permissive · top 15,000 on PyPI
pcodedmpDisassembles VBA p-code from Microsoft Office…
copyleft · top 5,000 on PyPI
sipSIP generates Python bindings for C and C++…
permissive · top 15,000 on PyPI
ctypesgenctypesgen parses C header files and…
permissive · top 15,000 on PyPI
lesscpyCompiles LESS stylesheets to CSS using Python,…
permissive · top 15,000 on PyPI
CppHeaderParserParses C++ header files and extracts their…
permissive · top 15,000 on PyPI
hello-worldA minimal package with no runtime dependencies,…
unclear · top 15,000 on PyPI