Repolode
pybind

pybind/pybind11

A header-only C++11 library for exposing C++ types and functions to Python, mainly to create Python bindings for existing C++ code.

Stars
18,028
Forks
2,331
Open issues
716
Last commit
11 hours ago

What is it?

pybind11 is a lightweight header-only library for exposing C++ types to Python and the reverse, mainly to build Python bindings for existing C++ code. Its goals and syntax resemble Boost.Python, but it drops the Boost dependency and relies only on the Python C API and the C++ standard library, using C++11 features to infer type information at compile time.

The library maps common C++ constructs to Python: functions taking and returning custom types by value, reference, or pointer, classes with methods and attributes, overloaded functions, exceptions, enums, callbacks, iterators, inheritance, STL containers, and std::shared_ptr. C++ classes with virtual methods can be extended in Python, and NumPy integration is included. It supports CPython 3.9+, PyPy, and GraalPy.

Because everything lives in a few headers, projects need no extra link libraries. The README also describes packaging examples for setuptools, scikit-build, and CMake.

Key features

  • 01Header-only, so no extra libraries need to be linked
  • 02Maps classes, overloads, enums, exceptions, and STL containers to Python
  • 03Lets C++ classes with virtual methods be extended in Python
  • 04Integrated NumPy support and buffer protocol access
  • 05Supports CPython 3.9+, PyPy, and GraalPy

Use cases

  • Wrapping an existing C++ library so Python code can call it
  • Exposing performance-critical C++ routines to Python scripts
  • Passing NumPy arrays between C++ code and Python without copying

Quick start

  1. 1

    Start from the Setuptools example project linked in the README

Things to know

  • Requires a C++11-capable compiler and CPython 3.9+, PyPy, or GraalPy.

Topics

FAQ

What is pybind11?
A header-only C++11 library for exposing C++ types and functions to Python, mainly to create Python bindings for existing C++ code. pybind11 is a lightweight header-only library for exposing C++ types to Python and the reverse, mainly to build Python bindings for existing C++ code. Its goals and syntax resemble Boost.Python, but it drops the Boost dependency and relies only on the Python C API and the C++ standard library, using C++11 features to infer type information at compile time.
Is pybind11 free to use? What license does it have?
pybind11 is open source under the Other license. Check the license terms before using it in commercial products.
Is pybind11 still maintained?
Actively maintained. The last commit to pybind11 was on Oct 24, 2026.
What can I use pybind11 for?
Wrapping an existing C++ library so Python code can call it Exposing performance-critical C++ routines to Python scripts Passing NumPy arrays between C++ code and Python without copying
How do I install pybind11?
Start from the Setuptools example project linked in the README
Where can I get pybind11?
The source code and installation instructions are on GitHub: https://github.com/pybind/pybind11

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects