pybind11 exposes C++ types in Python and vice versa with minimal boilerplate. It targets extension authors who want a compact alternative to large binding stacks.
Overview
pybind11 is a lightweight, header-only library for creating Python bindings to existing C++ code and bridging types between the languages. Its design goals parallel Boost.Python—reducing boilerplate through compile-time introspection—while avoiding a dependency on the full Boost distribution.
Core mappings include functions with value, reference, or pointer semantics; instance and static methods; overloaded functions; attributes; exceptions; enumerations; callbacks; iterators; operators; inheritance; STL containers; and smart pointers. Virtual C++ methods can be overridden from Python, and integrated NumPy support is documented.
The library stays in a small set of headers with no extra link libraries required. It supports CPython, PyPy, and GraalPy through an implementation-agnostic interface, uses C++11 features such as lambdas and variadic templates, and documents buffer protocol exposure, vectorized NumPy calls, slice access, and optional pickling for bound types.
Tutorial and API reference material is published on pybind11.readthedocs.io, with build examples for CMake, setuptools, scikit-build, and related tooling. Continuous integration exercises multiple operating systems, Python versions, and compilers, though specific OS names are not enumerated in the summary source beyond general platform coverage.
Key features
- Header-only binding macros
- C++11 lambda and STL support
- NumPy and buffer protocol integration
- Multiple and virtual inheritance
- Smart pointer reference counting
- Overloaded functions and operators
- CPython, PyPy, and GraalPy support
- Pickle support for bound types
Use cases
- Wrapping performance-critical C++ for Python
- Exposing C++ classes to Python packages
- Migrating off heavier binding frameworks
- NumPy-accelerated scientific extensions