Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. C/C++
  3. cppimport

cppimport

MITPython26.04.17

Import C++ files directly from Python with automatic compilation and transparent recompilation.

GitHubGitHub
1.2k stars74 forks0 contributors

What is cppimport?

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.

Target Audience

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.

Value Proposition

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.

Overview

Import C++ files directly from Python!

Use Cases

Best For

  • Quickly prototyping optimized C++ functions to speed up Python bottlenecks
  • Creating Python bindings for existing C++ libraries with minimal setup
  • Educational projects demonstrating C++/Python interop without complex build systems
  • Research code where iterative changes to both Python and C++ are common
  • Small to medium-sized extensions where a full CMake setup is overkill
  • Enabling transparent recompilation during development of mixed-language projects

Not Ideal For

  • Large projects with many source files requiring incremental compilation, as distutils lacks support and rebuilds can be slow
  • Windows development without pre-configured compilers like MinGW or Visual C++, due to limited CI testing and setup challenges
  • Teams needing build configurations separate from source code, since cppimport embeds Mako templates directly in C++ files
  • Applications requiring advanced build features like cross-compilation or custom toolchains, as cppimport relies on basic distutils

Pros & Cons

Pros

Seamless Edit-Test Workflow

Automatically compiles C++ on import, eliminating manual build steps and enabling rapid iteration, as shown in the quick example where importing triggers compilation.

Pybind11 Integration

Works seamlessly with pybind11 for creating Python bindings, making it straightforward to export C++ functions and classes, as demonstrated in the code snippets.

Transparent Recompilation

Uses checksums and dependency tracking to recompile only when sources change, ensuring up-to-date modules without unnecessary builds, as explained in the FAQ.

Concurrent Import Safety

Implements file locking to prevent race conditions during concurrent builds, making it safe for multi-process environments, with configurable timeouts.

Production Deployment Support

Includes a CLI tool to pre-compile modules for deployment, avoiding runtime compilation overhead, and allows release mode for faster startup.

Cons

No Incremental Compilation

Lacks support for incremental compilation in multi-file extensions due to distutils limitations, forcing full rebuilds that slow development for larger projects.

Platform-Specific Hurdles

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.

Embedded Configuration Complexity

Requires Mako templating within C++ files for build settings, which can obscure code and increase the risk of errors from mixed logic and syntax.

Dependency on Legacy Distutils

Relies on Python's distutils, which is deprecated and may lack features for modern build scenarios, limiting flexibility and future compatibility.

Frequently Asked Questions

Quick Stats

Stars1,229
Forks74
Contributors0
Open Issues10
Last commit5 months ago
CreatedSince 2016

Tags

#scientific-computing#performance-optimization#c-plus-plus#pybind11#mako-templates#build-tool

Built With

s
setuptools
M
Mako
P
Python
P
Pybind11
C
C++

Included in

C/C++70.6k
Auto-fetched 1 day ago

Related Projects

pybind11pybind11

Seamless operability between C++11 and Python

Stars18,025
Forks2,326
Last commit1 day ago
cythoncython

The most widely used Python to C compiler

Stars10,854
Forks1,636
Last commit2 days ago
ChakraCoreChakraCore

ChakraCore is an open source Javascript engine with a C API.

Stars9,262
Forks1,219
Last commit7 months ago
JerryScriptJerryScript

Ultra-lightweight JavaScript engine for the Internet of Things.

Stars7,421
Forks695
Last commit1 year ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub