1 of 5

pybind11 & nanobind

Axel Huebl [LBNL], Wenzel Jakob [EPFL], Aaron Gokaslan [Cornell],�Ralf Grosse-Kunstleve [Google], Henry Schreiner [Princeton],�Ethan Steinberg [Stanford]

Zero-dependency pure C++ CPython/PyPy interface

Trivial to add to a project

No special build requirements

No pre-compile phase

Not a new language

Like a missing C++ API for CPython!

2 of 5

pybind11 2.10.1, 2.10.2, 2.10.3, 2.10.4 & 2.11

  • Python 3.11 support
  • Simple GIL management option
  • Better cross-compile support for Windows and Pyodide
  • CMake improvements, better Meson support

pybind11 2.11 (release today)

  • 3.12 beta support (requires ABI 5)
  • PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF changing to default ON
  • Recursive container traits & customizable “is move constructible” behavior
  • Include <pybind11/type_caster_pyobject_ptr.h> for auto-wrapping PyObject *
  • Better cast errors (always includes type info!)
  • CMake 3.5+ required, 3.27 support

2.10.0 was released SciPy 2022,�2.11.0 is being released SciPy 2023!

3 of 5

Nanobind

Designed for Python 3.8+, C++17+, CMake 3.15+

Your bindings should conform to nanobind (vs. trying to support all of C++ in pybind11)

Focus on sizeperformancecompile time

Improvements:

Colocated C++/Python memory (2.3x smaller) • Less pointer chasing • Faster hash table • Vector calls • Not header only (has CMake helper) • Better lifetime management

New features:

0-copy N-dimensional arrays • CPython 3.12 Stable ABI support • Leak warnings • Low-level API

Minor new features:

Require returning existing Python instance • parameterized wrappers • Raw docstrings

Wenzel Jakob [EPFL]

4 of 5

Across the ecosystem! (nanobind_example)

[build-system]

requires = ["scikit-build-core", "nanobind"]

build-backend = "scikit_build_core.build"�

[project]

name = "nanobind-example"

version = "0.1.0"

[tool.scikit-build]

build-dir = "build/{wheel_tag}"

wheel.py-api = "cp312"

# Needed for full C++17 support

[tool.cibuildwheel.macos.environment]

MACOSX_DEPLOYMENT_TARGET = "10.14"

cmake_minimum_required(VERSION 3.15...3.26)

project(nanobind_example LANGUAGES CXX)

find_package(Python 3.8

REQUIRED COMPONENTS Interpreter Development.Module

OPTIONAL_COMPONENTS Development.SABIModule)

find_package(nanobind CONFIG REQUIRED)

nanobind_add_module(

nanobind_example_ext STABLE_ABI NB_STATIC

src/nanobind_example_ext.cpp

)

install(TARGETS nanobind_example_ext LIBRARY DESTINATION nanobind_example)

Requires nanobind 1.3.2+, scikit-build-core 0.4.3+, CPython 3.12.0b1+, cibuildwheel 2.13+, CMake 3.26.1+

On CPython 3.12+, this builds stable ABI wheels that support all future Python 3 releases with a single binary!

5 of 5

Plans

We are working on adopting some of the advancements from nanobind into pybind11.

New support for converting between arbitrary dimensional numpy arrays and Eigen::Tensors, which enables easier non-GIL processing of data from numpy

Dropping Python 3.6 next release.