skillfed

pcpp

A C99 preprocessor written in pure Python

pcpp v1.30 791.6K downloads/30d#5,046 on PyPI251
Permissive license BSD AGING released

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 pcpp

uv

uv add pcpp

poetry

poetry add pcpp

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Topic :: Software Development :: Build Tools

Tags

C preprocessor PythonC99 preprocessorheader file preprocessingC macro expansionbuild stage preprocessingsingle file includesmacro evaluation
c-preprocessingbuild-automationheader-processing

More Build Tools packages