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

Command What it does
init Create project structure
plugin <name> <files> Generate .cp from C++
rebuild / build Compile modules
get <module> Show module API
install <name> Install community module
update Update IncludeCPP
bug Report issue
--doc Show docs

rebuild options

includecpp rebuild --clean          # Full rebuild
includecpp rebuild --verbose        # See compiler output
includecpp rebuild -m crypto        # Rebuild specific module
includecpp rebuild -j 8             # 8 parallel jobs

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)

Notes

  • Builds go to AppData/IncludeCPP, source stays clean
  • SHA256 change detection, only rebuilds what changed
  • Parallel compilation by default

MIT License | v2.9.1 | 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.1.tar.gz (90.6 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.1-py3-none-any.whl (97.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: includecpp-2.9.1.tar.gz
  • Upload date:
  • Size: 90.6 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.1.tar.gz
Algorithm Hash digest
SHA256 f3a06da5d54667b3043b9628795af81362ec4376efc4fd734a677beefedc8f4f
MD5 4c205c794c84da50649bd8f86f0f794f
BLAKE2b-256 5bb2bb7a3e51c716971e56eb94e2c1132fe7a687ad014034d769c05a1a7e64e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: includecpp-2.9.1-py3-none-any.whl
  • Upload date:
  • Size: 97.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 93d3756bdb2e1e154f05297b15226f34b12480597ff7cfbe22a1821976033043
MD5 51a39fe29ac0e0e3d8214b57ab8c02ca
BLAKE2b-256 67b0e7fe3e2bd3fdf968931b5c98d6c23bbc104e0c443fd1cd641f7d0f3f32a3

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