Skip to main content

Professional C++ Python bindings with type-generic templates, pystubs and native threading

Project description

IncludeCPP

Write C++ code, use it in Python. Auto-generates pybind11 bindings.

pip install IncludeCPP

Setup

includecpp init

Creates cpp.proj, include/, plugins/.

Write C++ Code

Put your code in namespace includecpp:

// include/fast_list.cpp
#include <vector>

namespace includecpp {

class FastList {
public:
    void append(int val) { data.push_back(val); }
    int get(int i) { return data[i]; }
private:
    std::vector<int> data;
};

int add(int a, int b) { return a + b; }

}  // namespace includecpp

Without namespace includecpp, your code won't be found.

Generate Plugin

includecpp plugin fast_list include/fast_list.cpp

Creates plugins/fast_list.cp with detected classes, methods, functions.

Build

includecpp rebuild

Or includecpp build (same thing).

Use in Python

from includecpp import fast_list

my_list = fast_list.FastList()
my_list.append(42)
print(fast_list.add(1, 2))  # 3

Or classic style:

from includecpp import CppApi

api = CppApi()
fast_list = api.include("fast_list")

Commands

Use includecpp <command> --help for details. | Command | What it does | |---------|--------------| | init | Create project structure | | plugin <name> <files> | Generate .cp from C++ | | auto <plugin> | Regenerate .cp + build in one step | | rebuild / build | Compile modules | | get <module> | Show module API | | install <name> | Install community module | | update | Update IncludeCPP | | bug | Report issue | | --doc | Show docs |

Build Options

rebuild

includecpp rebuild                  # Standard build with caching
includecpp rebuild --clean          # Full rebuild, clear all caches
includecpp rebuild --fast           # Fast incremental (0.4s if unchanged)
includecpp rebuild --verbose        # See compiler output
includecpp rebuild -m crypto        # Rebuild specific module
includecpp rebuild -j 8             # 8 parallel jobs
includecpp rebuild --keep           # Keep generator between builds
includecpp rebuild --no-incremental # Force full recompilation
includecpp rebuild --this          # Build current dir as module 

auto

Regenerate plugin .cp file and build in one step:

includecpp auto fast_list           # Regenerate .cp + default build
includecpp auto fast_list --fast    # Regenerate .cp + fast build
includecpp auto fast_list -v        # Verbose output

Fast Mode

--fast uses object file caching for near-instant rebuilds:

Scenario Time
No changes ~0.4s
Source changed ~5-10s (only changed files)
Full rebuild ~30s
includecpp rebuild --fast <statements like 'modulename' or '--all'

Caches:

  • Object files (.o) - only recompile changed sources
  • CMake generator detection - check once, reuse
  • Compiler detection - check once, reuse

Clear all caches with --clean.

Incompatible Flags

These flag combinations will show a clear error:

Combination Why
--fast + --no-incremental --fast requires incremental compilation
--fast + --clean --fast uses caches, --clean deletes them
--fast + --this --this rebuilds current dir, incompatible with --fast
--incremental + --no-incremental Contradictory flags

Plugin Syntax (.cp files)

SOURCE(fast_list.cpp) fast_list

PUBLIC:

fast_list CLASS(FastList) {
    CONSTRUCTOR()
    METHOD(append)
    METHOD(get)
}

fast_list FUNC(add)

Overloaded Methods

MODULE CLASS(Circle) {
    METHOD_CONST(intersects, const Circle&)
    METHOD_CONST(intersects, const Rect&)
}

Templates

MODULE TEMPLATE_FUNC(maximum) TYPES(int, float, double)

MODULE STRUCT(Point) TYPES(int, float) {
    FIELD(T, x)
    FIELD(T, y)
}

Dependencies

DEPENDS(math_utils, geometry)

VSCode Support

Generates .pyi stubs automatically. Full autocomplete works.

Enable in cpp.proj:

{
  "CPI-IntelliSense": true
}

cpp.proj

{
  "project": "MyProject",
  "include": "/include",
  "plugins": "/plugins",
  "compiler": {
    "standard": "c++17",
    "optimization": "O3"
  }
}

Requirements

  • Python 3.8+
  • C++ compiler (g++, clang++, MSVC)
  • pybind11 (installed automatically)

Performance

  • Object caching: Only recompile changed .cpp → .o files
  • Generator caching: CMake/compiler detection runs once
  • Parallel compilation: Uses all CPU cores by default
  • SHA256 change detection: Skip unchanged modules
  • Builds in AppData: Source directory stays clean

Changelog

v2.9.10

  • New auto command: regenerate .cp + build in one step
  • --fast mode: 30s → 0.4s for unchanged builds
  • Object file caching (.o files)
  • CMake generator caching (detect once)
  • Incompatible flag validation with clear errors
  • Fixed --info pyd path detection

MIT License | v2.9.15 | GitHub

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

includecpp-2.9.15.tar.gz (94.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

includecpp-2.9.15-py3-none-any.whl (100.8 kB view details)

Uploaded Python 3

File details

Details for the file includecpp-2.9.15.tar.gz.

File metadata

  • Download URL: includecpp-2.9.15.tar.gz
  • Upload date:
  • Size: 94.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for includecpp-2.9.15.tar.gz
Algorithm Hash digest
SHA256 be4d0f966a46ddba664633d873f9083e40971677e998013494effa9ba54fd43c
MD5 91dfd928877bb0364b7b8635e4613096
BLAKE2b-256 11ef2bcf2193bd67ed280895eadc36d28a0acfd98e6a230cc9bf7201db98bbdf

See more details on using hashes here.

File details

Details for the file includecpp-2.9.15-py3-none-any.whl.

File metadata

  • Download URL: includecpp-2.9.15-py3-none-any.whl
  • Upload date:
  • Size: 100.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for includecpp-2.9.15-py3-none-any.whl
Algorithm Hash digest
SHA256 5193312cd2d145049a0ab817c64c980344f7b4eda21af32e3530eff8a9e9e751
MD5 d944e2e3ce1e57837764a823260c7bf2
BLAKE2b-256 014657dd038348eb059e42be753b3b70ec0acdcbe81383df9c746f36ffac275c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page