Import C++ files directly from Python with automatic compilation and transparent recompilation.
cppimport is a Python library that allows developers to import C++ source files directly as Python modules, automatically handling compilation and binding via pybind11. It solves the problem of manual compilation steps in mixed Python/C++ workflows, enabling rapid iteration on performance-critical code.
Python developers who need to integrate C++ code for performance reasons, such as data scientists, engineers working on numerical computing, or anyone extending Python with native modules.
Developers choose cppimport because it dramatically simplifies the development cycle for Python extensions, offering automatic recompilation, seamless integration with pybind11, and a configuration system that keeps build logic close to the source code.
Import C++ files directly from Python!
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically compiles C++ on import, eliminating manual build steps and enabling rapid iteration, as shown in the quick example where importing triggers compilation.
Works seamlessly with pybind11 for creating Python bindings, making it straightforward to export C++ functions and classes, as demonstrated in the code snippets.
Uses checksums and dependency tracking to recompile only when sources change, ensuring up-to-date modules without unnecessary builds, as explained in the FAQ.
Implements file locking to prevent race conditions during concurrent builds, making it safe for multi-process environments, with configurable timeouts.
Includes a CLI tool to pre-compile modules for deployment, avoiding runtime compilation overhead, and allows release mode for faster startup.
Lacks support for incremental compilation in multi-file extensions due to distutils limitations, forcing full rebuilds that slow development for larger projects.
Windows support is not fully tested in CI, requiring manual compiler setup and potentially breaking in environments without proper toolchains, as noted in the README.
Requires Mako templating within C++ files for build settings, which can obscure code and increase the risk of errors from mixed logic and syntax.
Relies on Python's distutils, which is deprecated and may lack features for modern build scenarios, limiting flexibility and future compatibility.