Navigate:
All Repospybind11
~$PYBIND0.1%

pybind11: C++ and Python interoperability bindings

Header-only library creating minimal-boilerplate C++ Python bindings.

LIVE RANKINGS • 06:53 AM • STEADY
OVERALL
#184
8
DEVELOPER TOOLS
#35
1
30 DAY RANKING TREND
ovr#184
·Devel#35
STARS
17.6K
FORKS
2.3K
DOWNLOADS
7D STARS
+10
7D FORKS
+2
See Repo:
Share:

Learn more about pybind11

pybind11 is a C++ library designed to create Python bindings for existing C++ code. It operates as a header-only implementation that leverages C++11 features like tuples, lambda functions, and variadic templates to generate bindings with minimal code. The library supports CPython 3.8+, PyPy 7.3.17+, and GraalPy 24.1+, and can map C++ constructs including functions, methods, classes, exceptions, enumerations, STL containers, and smart pointers to their Python equivalents. Common use cases include wrapping performance-critical C++ libraries for use in Python applications and integrating existing C++ codebases into Python projects.

pybind11

1

Header-only implementation

The core library consists of approximately 4,000 lines of code contained entirely in header files with no external dependencies beyond Python and the C++ standard library. This eliminates the need to link against additional libraries or manage complex build configurations.

2

C++11 language features

pybind11 uses modern C++ constructs to reduce boilerplate compared to earlier binding approaches. Type information is inferred at compile time through introspection, and function signatures are precomputed using constexpr, resulting in smaller binary sizes.

3

Broad C++ feature coverage

The library maps a wide range of C++ constructs to Python including virtual methods, multiple inheritance, custom operators, internal reference counting, and integration with NumPy arrays. It also supports C++11 lambda functions with captured variables and move semantics for efficient data transfer.


// example.cpp
#include <pybind11/pybind11.h>

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

PYBIND11_MODULE(example, m) {
    m.def("add", &add, "Add two numbers");
}

# Python usage
import example
result = example.add(5, 3)
print(result)  # Output: 8

vv3.0.1

Patch release fixing multiple sub-interpreter crashes and segfaults; removes subinterpreter-specific exception handling to improve stability.

  • Update if using sub-interpreters: concurrent creation now blocked in Python 3.12 to avoid stdlib concurrency bugs.
  • Fixes pointer-to-enum casting errors and module re-import crashes; reduces template depth for functions with many parameters.
vv3.0.0

ABI-breaking release drops Python 3.7, PyPy 3.8/3.9, and CMake <3.15; adds smart_holder, multi-phase init, and subinterpreter support.

  • Migrate to smart_holder with `py::class_<T, py::smart_holder>` for bidirectional unique_ptr/shared_ptr conversions and trampoline support.
  • Enable subinterpreter support by adding `py::multiple_interpreters::per_interpreter_gil()` as third parameter to PYBIND11_MODULE calls.
vv3.0.0rc4

ABI bump (expected last before stable 3.0.0); fixes smart_holder support for const-only and shared_ptr<const T>, eliminates cross-DSO RTTI reliance on macOS.

  • Expect ABI breakage; recompile all extensions built against earlier 3.0.0 release candidates.
  • Update smart_holder code if using const-only smart pointers or shared_ptr<const T> in py::init().


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers