pybind11 is a header-only library that creates Python bindings for C++ code by exposing C++ types in Python and vice versa.
The library solves the problem of writing boilerplate-heavy Python extension modules for existing C++ codebases. It uses compile-time introspection to infer type information, allowing developers to declare bindings with minimal code. Unlike Boost.Python, which requires the entire Boost suite as a dependency, pybind11 is self-contained and leverages C++11 features like variadic templates and lambda functions to achieve a compact implementation of only around four thousand lines of core code. It depends solely on Python and the C++ standard library.
Teams should adopt pybind11 when they need to expose C++ functionality to Python without maintaining heavy dependencies or writing extensive wrapper code. The tool suits projects that already have a C++ codebase and want to provide Python interfaces, particularly those targeting performance-critical operations. It handles a broad range of C++ constructs including custom data structures, methods, overloaded functions, inheritance, STL containers, smart pointers, and virtual methods that can be overridden in Python. The library also provides integrated NumPy support for scientific computing workflows. It supports CPython, PyPy, and GraalPy implementations.
The project maintains a substantial base of real-world adopters, as evidenced by the fact that nearly all open issues originate from outside users rather than the core team. Responses to issues and pull requests typically arrive within one to two weeks. Development activity concentrates on bug fixes, build system improvements, and documentation work.