pybind11 3.0 Overhauls C++ to Python Bindings With Smart Pointers

pybind11 crosses into 3.x with a merged smart-holder, subinterpreter support, Python 3.14 free-threading, and a required ABI bump on Unix.

·
·
·
pybind11 3.0 Overhauls C++ to Python Bindings With Smart PointersPRO
  • pybind11 has shipped its 3.0 line with 3.0.4 as the latest patch on the branch.
  • Smart-holder branch merged, resolving long-standing unique_ptr and shared_ptr issues via py::classh.
  • Multi-phase init, subinterpreter support, and free-threading tags for Python 3.14t are now available.
  • Support added for Python 3.14, GraalPy, PyPy 3.11, iOS; Python 3.7 and old CMake dropped.
  • First required ABI bump on Unix in years, all pybind11 extensions should be rebuilt.
  • CMake defaults to FindPython; PYTHON_* variables are deprecated in favor of Python_*.

The venerable C++ to Python bindings library pybind11 has crossed into the 3.x line, with a fresh 3.0.4 patch now shipping on top of the biggest overhaul the project has seen in years. The upgrade guide confirms that most existing extensions should build and run without modification, though minor adjustments may be needed in rare cases. Extensions built with 3.0 are not ABI-compatible with those built against 2.13.

If you have C++ code exposed to Python anywhere in your ML stack (custom CUDA kernels, tensor ops, simulation environments, feature extractors), this is a release worth tracking.

What actually landed

The headline items in 3.0 are unusually dense for a library that has spent most of its life doing careful, incremental work. Version 3.0 includes an ABI bump (the first required bump in many years on Unix), the smart-holder branch, multi-phase init and subinterpreter support, py::native_enum, an interface to warnings, typing improvements, and more. CMake now defaults to FindPython mode.

A few of these deserve unpacking:

  • Smart holder merged. After years in development, Google's smart-holder branch has landed. You can now opt into a custom smart pointer, or use any other smart pointer since holders are templated. There is also a py::classh shortcut. The new holder supports shared/unique pointer conversion, disowning a Python object, trampoline objects, const smart pointers, and std::enable_shared_from_this.
  • Subinterpreters and free-threading.

Pro article

This story is for Pro members

You've reached the end of the free preview. Upgrade to AlphaSignal Pro to read the full article - and everything else behind the paywall.

Trending
  • No trending articles

Comments

avatar

Next Reads