Starting with version 1.8.0, pybind11 releases use a semantic versioning policy.
Changes will be added here periodically from the “Suggested changelog entry” block in pull request descriptions.
Bug fixes:
Fixed compilation error in type_caster_enum_type when casting pointer-to-enum types. Added pointer overload to handle dereferencing before enum conversion. #5776
Implement binary version of make_index_sequence to reduce template depth requirements for functions with many parameters. #5751
Subinterpreter-specific exception handling code was removed to resolve segfaults. #5795
Fixed issue that caused PYBIND11_MODULE code to run again if the module was re-imported after being deleted from sys.modules. #5782
Prevent concurrent creation of sub-interpreters as a workaround for stdlib concurrency issues in Python 3.12. #5779
Fixed potential crash when using cpp_function objects with sub-interpreters. #5771
Fixed non-entrant check in implicitly_convertible(). #5777
Support C++20 on platforms that have older c++ runtimes. #5761
Fix compilation with clang on msys2. #5757
Avoid nullptr dereference warning with GCC 13.3.0 and python 3.11.13. #5756
Fix potential warning about number of threads being too large. #5807
Documentation:
Improve buffer_info type checking in numpy docs. #5805
Replace robotpy-build with semiwrap in the binding tool list. #5804
Show nogil in most examples. #5770
Fix py::trampoline_self_life_support visibility in docs. #5766
Tests:
Avoid a spurious warning about DOWNLOAD_CATCH being manually specified. #5803
Fix an IsolatedConfig test. #5768
CI:
Internal:
slots (reads better). #5793Pybind11 3.0 includes an ABI bump, the first required bump in many years on Unix (Windows has had required bumps more often). This release contains 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. Please check our upgrade guide for more info on upgrading!
Support for Python 3.14, 3.14t, GraalPy, and PyPy 3.11 has been added, while legacy support for Python 3.7, PyPy 3.8/3.9, and CMake <3.15 has been removed. Most deprecated features have been kept for this release, but anything producing a warning in 3.0 may be removed in a future 3.x version. We also now have a deprecation page.
New Features:
The smart_holder branch has been merged, enabling py::class_<T, py::smart_holder>, which handles two-way conversion with std::unique_ptr<T> and std::shared_ptr<T> (simultaneously), disowning a Python object being passed to std::unique_ptr<T>, trampoline objects, and std::enable_shared_from_this. #5542
Added support for std::shared_ptr<const T> in py::init() when using py::smart_holder, complementing existing support for std::unique_ptr<const T>. #5731
Support const-only smart pointers. #5718
Eliminate cross-DSO RTTI reliance from trampoline_self_life_support functionality, smart_holder deleter detection, and other smart_holder bookkeeping. Resolves platform-specific issues on macOS related to cross-DSO dynamic_cast and typeid mismatches. #5728 (replaces #5700)
Changed PYBIND11_MODULE macro implementation to perform multi-phase module initialization (PEP 489) behind the scenes. #5574 and avoid destruction #5688
Support for sub-interpreters (both isolated (with separate GILs) and legacy (with a global GIL). Add the py::multiple_interpreters::per_interpreter_gil() tag (or, py::multiple_interpreters::shared_gil() for legacy interpreter support) to PYBIND11_MODULE calls (as the third parameter) to indicate that a module supports running with sub-interpreters. #5564
Rename macro PYBIND11_SUBINTERPRETER_SUPPORT -> PYBIND11_HAS_SUBINTERPRETER_SUPPORT to meet naming convention. #5682
Allow subinterpreter support to be disabled if defined to 0. This is mostly an emergency workaround, and is not exposed in CMake. #5708 and #5710
Modify internals pointer-to-pointer implementation to not use thread_local (better iOS support). #5709
Support implementations without subinterpreter support. #5732
Changed PYBIND11_EMBEDDED_MODULE macro implementation to perform multi-phase module initialization (PEP 489) behind the scenes and to support py::mod_gil_not_used(), py::multiple_interpreters::per_interpreter_gil() and py::multiple_interpreters::shared_gil(). #5665 and consolidate code #5670.
Added API in pybind11/subinterpreter.h for embedding sub-intepreters (requires Python 3.12+). #5666
py::native_enum was added, for conversions between Python's native (stdlib) enum types and C++ enums. #5555
Support py::numpy_scalar<> / py::make_scalar() for NumPy types. #5726
A py::release_gil_before_calling_cpp_dtor option (for py::class_) was added to resolve the long-standing issue #1446. #5522
Add dtype::normalized_num and dtype::num_of. #5429
Add support for array_t<handle> and array_t<object>. #5427
Added py::warnings namespace with py::warnings::warn and py::warnings::new_warning_type that provides the interface for Python warnings. #5291
stl.h list|set|map_caster were made more user friendly: it is no longer necessary to explicitly convert Python iterables to tuple(), set(), or map() in many common situations. #4686
The array_caster in pybind11/stl.h was enhanced to support value types that are not default-constructible. #5305
pybind11/conduit/pybind11_platform_abi_id.h was factored out, to maximize reusability of PYBIND11_PLATFORM_ABI_ID (for other Python/C++ binding systems). Separately, a note was added to explain that the conduit feature only covers from-Python-to-C++ conversions. #5375 | #5740
Added support for finding pybind11 using pkgconf distributed on pypi. #5552
Support --extension-suffix on the pybind11 command. #5360
Add semi-public API: pybind11::detail::is_holder_constructed and update example for pybind11::custom_type_setup in documentation. #5669
Added py::scoped_critical_section to support free-threaded mode. #5684 | #5706
New Features / fixes (typing):
type_caster. Updated stl/filesystem to use correct arg/return type hints. Updated pybind11::typing to use correct arg/return type hints for nested types. #5450py::capsule to type.CapsuleType. #5567typing.SupportsInt and typing.SupportsFloat. Update Final to be narrower type hint. Make std::function match Callable type. Fix io_name bug in attr_with_type_hint. #5540.noconvert(). #5486attr_with_type for declaring attribute types and Final, ClassVar type annotations. #5460py::pos_only when only have the self argument. Make arguments for auto-generated dunder methods positional-only. #5403py::Args and py::KWArgs to enable custom type hinting of *args and **kwargs (see PEP 484). #5357numpy.typing.NDArray and numpy.typing.ArrayLike. #5212numpy.object_ instead of object. #5571collections.abc in type hints and convertible checks of STL casters and py::buffer. #5566typing and collections.abc type hint ambiguity. #5663typing_extensions alternatives for all types that need them. #5693Removals:
make_simple_namespace (added in 2.8.0, deprecated in 2.8.1). #5597PYBIND11_NUMPY_1_ONLY has been removed. #5595.get_type (deprecated in pybind11 2.6 in 2020). #5596Bug fixes:
__file__ on submodules. #5584. Except on embedded modules. #5650attr_with_type_hint to allow objects to be in attr_with_type_hint. #5576-Wmaybe-uninitialized warning suppression was added in pybind11/eigen/matrix.h. #5516PYBIND11_WARNING_POP was incorrectly defined as PYBIND11_PRAGMA(clang diagnostic push). #5448PYBIND11_PLATFORM_ABI_ID (which is used in composing PYBIND11_INTERNALS_ID) was modernized to reflect actual ABI compatibility more accurately. #4953 | #5439bind_map, print the key in KeyError if it does not exist. #5397pybind11::builtin_exception is now explicitly exported when linked to libc++. #5390py::args and py::kwargs. #5381_DEBUG macro to 1 instead of defining it without value. #5639py::slice to be equivalent to :: in Python. #5620Bug fixes and features (CMake):
COMPAT mode that sets some of the old variables to ease transition. #5553PYTHON_MODULE_EXTENSION may not respect SETUPTOOLS_EXT_SUFFIX during cross-compilation. #5495CMAKE_BUILD_TYPE None. #5392NO_EXTRAS adding pybind11::windows_extras anyway. #5378--fresh. #5668compile_commands.json. #5685Bug fixes (free-threading):
all_type_info() was fixed. #5419try_translate_exceptions in the free-threaded build for internal locking. #5362Internals:
Consolidated all PYBIND11_HAS_... feature macros into pybind11/detail/common.h to streamline backward compatibility checks and simplify internal refactoring. This change ensures consistent macro availability regardless of header inclusion order. #5647
pybind11/gil_simple.h was factored out from pybind11/gil.h, so that it can easily be reused. #5614
Use CPython macros to construct PYBIND11_VERSION_HEX. #5683
Documentation:
Improved reference_internal policy documentation. #5528
A new “Double locking, deadlocking, GIL” document was added. #5394
Add documenting for free-threading and subinterpreters. #5659
Tests:
Download the final Catch2 2.x release if Catch download is requested. #5568
Explicitly used signed char for two numpy dtype tests. As seen when compiling using clang on Linux with the -funsigned-char flag. #5545
CI testing now includes -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls in some jobs. #5523
Add nightly wheels to scientific-python's nightly wheelhouse. #5675
Expect free-threaded warning when loading a non-free-threaded module. #5680
Run pytest under Python devmode. #5715
New and removed platforms:
Support Python 3.14 (beta 1+). #5646
Added support for GraalPy Python implementation (https://github.com/oracle/graalpython). #5380
Support and test iOS in CI. #5705
Support for PyPy 3.8 and 3.9 was dropped. #5578
Support for Python 3.7 was removed. (Official end-of-life: 2023-06-27). #5191
Support for CMake older than 3.15 removed. CMake 3.15-4.0 supported. #5304 and fix regression #5691.
Use scikit-build-core for the build backend for the PyPI pybind11. The CMake generation has been moved to the sdist->wheel step. PYBIND11_GLOBAL_SDIST has been removed. #5598 and updated docs/ci. #5676
clang 20 tested and used for clang-tidy. #5692
Drop testing on MSVC 2019 (as it is being removed from GitHub). #5712
Support Windows C++20 and Linux C++23 in tests. #5707
New Features:
self._pybind11_conduit_v1_() method is automatically added to all py::class_-wrapped types, to enable type-safe interoperability between different independent Python/C++ bindings systems, including pybind11 versions with different PYBIND11_INTERNALS_VERSION's. Supported on pybind11 2.11.2, 2.12.1, and 2.13.6+. #5296Bug fixes:
__cpp_nontype_template_args instead of __cpp_nontype_template_parameter_class. #5330Documentation:
Bug fixes:
\\?\ prefix). #5321-Wpedantic in C++20 mode. #5322<ranges> support for py::tuple and py::list. #5314Bug fixes:
Documentation:
Bug fixes:
New Features:
pybind11::detail::type_caster_std_function_specializations feature was added, to support specializations for std::function's with return types that require custom to-Python conversion behavior (to primary use case is to catch and convert exceptions). #4597Changes:
PyMutex instead of std::mutex for internal locking in the free-threaded build. #5219Bug fixes:
gil_safe_call_once_and_store thread-safe in free-threaded CPython. #5246#include <algorithm> in pybind11/typing.h was added to fix build errors (in case user code does not already depend on that include). #5208Tests:
New Features:
Typing.Callable[..., T]. #5202Bug fixes:
New Features:
py::mod_gil_not_used() tag to indicate if a module supports running with the GIL disabled. #5148py::list gained a .clear() method. #5153Union, Optional, type[T], typing.TypeGuard, typing.TypeIs, typing.Never, typing.NoReturn and typing.Literal was added to pybind11/typing.h. #5166 #5165 #5194 #5193 #5192PYBIND11_USE_CROSSCOMPILING is enabled, then CMAKE_CROSSCOMPILING will be respected and will keep pybind11 from accessing the interpreter during configuration. Several CMake variables will be required in this case, but can be deduced from the environment variable SETUPTOOLS_EXT_SUFFIX. The default (currently OFF) may be changed in the future. #5083Bug fixes:
PyObject * return type was fixed. #5156py::ssize_t from .ref_count() instead of int. #5139operator& overrides was fixed. #5189Documentation:
Tests:
CI:
macos-13 (Intel) for CI jobs for now (will drop Python 3.7 soon). #5109Other:
New Features:
self._pybind11_conduit_v1_() method is automatically added to all py::class_-wrapped types, to enable type-safe interoperability between different independent Python/C++ bindings systems, including pybind11 versions with different PYBIND11_INTERNALS_VERSION's. Supported on pybind11 2.11.2, 2.12.1, and 2.13.6+. #5296New Features:
pybind11 now supports compiling for NumPy 2. Most code shouldn't change (see upgrade-guide-2.12 for details). However, if you experience issues you can define PYBIND11_NUMPY_1_ONLY to disable the new support for now, but this will be removed in the future. #5050pybind11/gil_safe_call_once.h was added (it needs to be included explicitly). The primary use case is GIL-safe initialization of C++ static variables. #4877py::make_iterator, py::make_key_iterator, py::make_value_iterator. #4834py::set_error() functions were added and the documentation was updated accordingly. In particular, py::exception<>::operator() was deprecated (use one of the new functions instead). The documentation for py::exception<> was further updated to not suggest code that may result in undefined behavior. #4772Bug fixes:
pybind11/numpy.h now imports NumPy's multiarray and _internal submodules with paths depending on the installed version of NumPy (for compatibility with NumPy 2). #4857py::typing::Iterator<T>, py::typing::Iterable<T>. #4832py::function as Callable in docstring. #4829PYBIND11_INTERNALS_VERSION for MSVC, which unlocks two new features without creating additional incompatibilities. #4819bind_map with using declarations. #4952py::detail::concat usage to avoid ADL selecting one from somewhere else, such as modernjson's concat. #4955class_ for KeysView/ValuesView/ItemsView. #4985PyObject_VisitManagedDict() and PyObject_ClearManagedDict() on Python 3.13 and newer. #4973make_static_property_type() to make it compatible with Python 3.13. #4971make_iterator, make_key_iterator, make_value_iterator. #4876py::buffer, py::sequence and py::handle (to Buffer, Sequence, Any). #4831base_enum.__str__ docstring. #4827typing.h to annotate tuple, dict, list, set, and function. #4259handle_type_name specialization to type-hint variable length tuples. #5051PYBIND11_FINDPYTHON to OFF will force the old FindPythonLibs mechanism to be used. #5042PYBIND11_PYTHON_EXECUTABLE_LAST for the first cmake run. #4856pkg_resources if importlib.metadata available. #4941Python_ADDITIONAL_VERSIONS (classic search) now includes 3.12. #4909pybind11.pc is now relocatable by default as long as install destinations are not absolute paths. #4830pybind11_strip is no longer automatically applied when CMAKE_BUILD_TYPE is unset. #4780DEBUG_POSFIX correctly for debug builds. #4761Documentation:
functions.rst. #4791CI:
Other:
assert() was added to help Coverty avoid generating a false positive. #4817New Features:
self._pybind11_conduit_v1_() method is automatically added to all py::class_-wrapped types, to enable type-safe interoperability between different independent Python/C++ bindings systems, including pybind11 versions with different PYBIND11_INTERNALS_VERSION's. Supported on pybind11 2.11.2, 2.12.1, and 2.13.6+. #5296Changes:
PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF is now provided as an option for disabling the default-on PyGILState_Check()'s in pybind11::handle's inc_ref() & dec_ref(). #4753PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF was disabled for PyPy in general (not just PyPy Windows). #4751New features:
pybind11::detail::is_move_constructible trait can be specialized for cases in which std::is_move_constructible does not work as needed. This is very similar to the long-established pybind11::detail::is_copy_constructible. #4631recursive_container_traits. #4623pybind11/type_caster_pyobject_ptr.h was added to support automatic wrapping of APIs that make use of PyObject *. This header needs to included explicitly (i.e. it is not included implicitly with pybind/pybind11.h). #4601format_descriptor<> & npy_format_descriptor<> PyObject * specializations were added. The latter enables py::array_t<PyObject *> to/from-python conversions. #4674buffer_info gained an item_type_is_equivalent_to<T>() member function. #4674capsule API gained a user-friendly constructor (py::capsule(ptr, "name", dtor)). #4720Changes:
PyGILState_Check()'s in pybind11::handle's inc_ref() & dec_ref() are now enabled by default again. #4246py::initialize_interpreter() using PyConfig_InitPythonConfig() instead of PyConfig_InitIsolatedConfig(), to obtain complete sys.path. #4473PYBIND11_DETAILED_ERROR_MESSAGES is not defined. This increases binary sizes slightly (~1.5%) but the error messages are much more informative. #4463std::array-list caster was fixed. Previously, signatures included the size of the list in a non-standard, non-spec compliant way. The new format conforms to PEP 593. Tooling for processing the docstrings may need to be updated accordingly. #4679noexcept(true) in C++17. #4593PYBIND11_INTERNALS_VERSION 5 (default for Python 3.12+), MSVC builds use std::hash<std::type_index> and std::equal_to<std::type_index> instead of string-based type comparisons. This resolves issues when binding types defined in the unnamed namespace. #4319__notes__ (introduced with Python 3.11) are now added to the error_already_set::what() output. #4678Build system improvements:
FindPythonInterp is not present. #4719lto checks and target generation when CMAKE_INTERPROCEDURAL_OPTIMIZATION is defined. #4643-stdlib=libc++, not needed for modern Pythons (macOS 10.9+). #4639Changes:
python3 -m pybind11 gained a --version option (prints the version and exits). #4526Bug Fixes:
gil_scoped_release RAII is non-copyable. #4490Changes:
PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF, will be enabled in 2.11). #4432inc_ref/dec_ref are called with an invalid GIL state. #4427 #4436Bug Fixes:
Changes:
scoped_interpreter constructor taking PyConfig. #4330pybind11/eigen/tensor.h adds converters to and from Eigen::Tensor and Eigen::TensorMap. #4201PyGILState_Check()'s were integrated to pybind11::handle inc_ref() & dec_ref(). The added GIL checks are guarded by PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF, which is the default only if NDEBUG is not defined. (Made non-default in 2.10.3, will be active in 2.11) #4246KeysView, ValuesView and ItemsView in bind_map. #4353Bug fixes:
PyEval_InitThreads() call to the correct location. #4350Build system improvements:
find_package(pybind11 CONFIG) multiple times from separate directories in the same CMake project and properly link Python (new mode). #4401multiprocessing_set_spawn in pytest fixture for added safety. #4377This is the first version to fully support embedding the newly released Python 3.11.
Changes:
pybind11::capsule constructor to take null destructor pointers. #4221embed.h was changed so that PYTHONPATH is used also with Python 3.11 (established behavior). #4119PYBIND11_SIMPLE_GIL_MANAGEMENT option was added (cmake, C++ define), along with many additional tests in test_gil_scoped.py. The option may be useful to try when debugging GIL-related issues, to determine if the more complex default implementation is or is not to blame. See #4216 for background. WARNING: Please be careful to not create ODR violations when using the option: everything that is linked together with mutual symbol visibility needs to be rebuilt. #4216PYBIND11_EXPORT_EXCEPTION was made non-empty only under macOS. This makes Linux builds safer, and enables the removal of warning suppression pragmas for Windows. #4298Bug fixes:
UnicodeDecodeError was not propagated from various py::str ctors when decoding surrogate utf characters. #4294make_iterator. This broke at least one valid use case. May revisit later. #4234void* (regression in 2.10.0). #4275char8_t support (regression in 2.9). #4278error_already_set::what(). #4297overload_cast. #4188py::error_already_set implementation, related to PR #1895 released with v2.10.0. #4079std::forward_like is available. #4136get_local_internals() was made compatible with finalize_interpreter(), fixing potential freezes during interpreter finalization. #4192Performance and style:
PYBIND11_OBJECT macros and enforce the clang-tidy checks modernize-use-equals-default in macros as well. #4017PyObject_GenericGetDict and PyObject_GenericSetDict for handling dynamic attribute dictionaries. #4106PYBIND11_NAMESPACE instead of using pybind11 when opening namespaces. Using namespace declarations and namespace qualification remain the same as pybind11. This is done to ensure consistent symbol visibility. #4098detail::forward_like as constexpr. #4147arg_v arguments. #4219None. #4269Build system improvements:
PYBIND11_PYTHONLIBS_OVERRWRITE OFF. #4195CMAKE_BUILD_TYPE is set to DEBUG instead of Debug. #4078Removed support for Python 2.7, Python 3.5, and MSVC 2015. Support for MSVC 2017 is limited due to availability of CI runners; we highly recommend MSVC 2019 or 2022 be used. Initial support added for Python 3.11.
New features:
py::anyset & py::frozenset were added, with copying (cast) to std::set (similar to set). #3901type_caster<std::monostate> was added. std::monostate is a tag type that allows std::variant to act as an optional, or allows default construction of a std::variant holding a non-default constructible type. #3818pybind11::capsule::set_name added to mutate the name of the capsule instance. #3866dtype.num, dtype.byteorder, dtype.flags and dtype.alignment added. #3868Changes:
error_already_set is now safer and more performant, especially for exceptions with long tracebacks, by delaying computation. #1895str bindings. #3826PYBIND11_OBJECT_CVT and PYBIND11_OBJECT_CVT_DEFAULT macro can now be used to define classes in namespaces other than pybind11. #3797PYBIND11_DETAILED_ERROR_MESSAGES instead of requiring NDEBUG, allowing use with release builds if desired. #39130 to pybind11::handle is now disabled. #4008Bug fixes:
pybind11::weakref() fails. #3739module_::def_submodule was missing proper error handling. This is fixed now. #3973error_already_set was made safer and the highly opaque “Unknown internal error occurred” message was replaced with a more helpful message. #3982error_already_set::what() now handles non-normalized exceptions correctly. #3971std::experimental::filesystem. #3840-Wfree-nonheap-object warnings produced by GCC by avoiding returning pointers to static objects with return_value_policy::take_ownership. #3946PYBIND11_NAMESPACE __attribute__((visibility("hidden"))) inconsistencies are now fixed (affects only unusual environments). #4043pybind11::detail::get_internals() is now resilient to in-flight Python exceptions. #3981Performance and style:
(object &&key) to reference steal the object when using python types as keys. This prevents unnecessary reference count overhead for attr, dictionary, tuple, and sequence look ups. Added additional regression tests. Fixed a performance bug the caused accessor assignments to potentially perform unnecessary copies. #3970make_iterator. #3980error_guard to one of the dtors. #3958strip_padding for numpy. #3994stl_bind.h bindings now take slice args as a const-ref. #3852PyErr_Restore is called only once. #3872make_iterator functions. #3860strdup_gaurd. #3905misc-definitions-in-headers, modernize-loop-convert, and modernize-use-nullptr. #3881 #3988Build system improvements:
Backend and tidying up:
#include <iostream> was removed from the pybind11/stl.h header. Your project may break if it has a transitive dependency on this include. The fix is to “Include What You Use”. #3928setup.py <command> usage in internal tests. #3734Changes:
__index__ method on Python <3.8 too. #3700Bug fixes:
PYBIND11_TYPE_CASTER now uses fully qualified symbols, so it can be used outside of pybind11::detail. #3758get_type_override. #3774VISIBILITY_INLINES_HIDDEN. #3721Build system improvements:
sysconfig module to determine installation locations on Python >= 3.10, instead of distutils which has been deprecated. #3764str() of dtypes. #3682Backend and tidying up:
readability-qualified-auto, readability-braces-around-statements, cppcoreguidelines-prefer-member-initializer, clang-analyzer-optin.performance.Padding, cppcoreguidelines-pro-type-static-cast-downcast, and readability-inconsistent-declaration-parameter-name. #3702, #3699, #3716, #3709Changes:
py::raise_from to TypeError when casting from C++ to Python. This will give additional info if Python exceptions occur in the caster. Adds a test case of trying to convert a set from C++ to Python when the hash function is not defined in Python. #3605py::raise_from. This attaches the nested exceptions in Python using the __cause__ field. #3608raise_from if a pybind11 function runs out of overloads. #3671py::multiple_inheritance is now only needed when C++ bases are hidden from pybind11. #3650 and #3659Bug fixes:
numpy.h that causes MSVC C4800 warnings when compiling against Python 3.10 or newer. #3669py::bool_ and py::float_ as bool and float respectively. #3622Build system improvements:
CMAKE_ARGS to override CMake args in pybind11's own setup.py. #3577This is the last version to support Python 2.7 and 3.5.
New Features:
py::args to be followed by other arguments; the remaining arguments are implicitly keyword-only, as if a py::kw_only{} annotation had been used. #3402Changes:
std::string_view. #3521_ with const_name in internals, avoid defining pybind::_ if _ defined as macro (common gettext usage) #3423Bug fixes:
std::forward calls to some cpp_function overloads. #3443python dev label. #3419Eigen::MappedSparseMatrix with Eigen::Map<Eigen::SparseMatrix<...>> for Eigen 3.3+. #3499Build system improvements:
-g in $CFLAGS and $CPPFLAGS are no longer overridden by .Pybind11Extension. #3436setup_helpers. #3548mips64 and ppc64le (reported broken). #3557Changes and additions:
py::module_::import("types").attr("SimpleNamespace"). #3374AttributeError. Useful for defining custom __setattr__ and __getattr__ methods. #3387Fixes:
std::optional types. #3376PyCodeObject on Python 3.9+ (moving toward support for Python 3.11a1) #3368eigen.h was fixed (originally PR #3343). The bug was unmasked by newly added static_assert's in the Eigen 3.4.0 release. #3352make_key_iterator/make_value_iterator if dereferencing the iterator returned a temporary value instead of a reference. #3348New features:
py::raise_from to enable chaining exceptions. #3215register_local_exception_translator(ExceptionTranslator&& translator) instead of register_exception_translator(ExceptionTranslator&& translator) to keep your exception remapping code local to the module. #2650make_simple_namespace function for instantiating Python SimpleNamespace objects. Deprecated in 2.8.1. #2840pybind11::scoped_interpreter and initialize_interpreter have new arguments to allow sys.argv initialization. #2341view to view arrays with a different datatype. #987reshape on arrays. #984__new__ methods on classes by fixing bug preventing overriding methods if they have non-pybind11 siblings. #3265make_value_iterator(), and fix make_key_iterator() to return references instead of copies. #3293bind_map: #3310.items from an iterator to a dictionary view..keys and .values (both dictionary views).__contains__ to take any object.pybind11::custom_type_setup was added, for customizing the PyHeapTypeObject corresponding to a class, which may be useful for enabling garbage collection support, among other things. #3287Changes:
__file__ constant when running eval_file in an embedded interpreter. #3233std::optional now accepted in py::slice constructor. #1101str, bytes, bytearray, tuple, list now consistently support passing ssize_t values for sizes and indexes. Previously, only size_t was accepted in several interfaces. #3219PYBIND11_TLS_REPLACE_VALUE arguments more than once. #3290Fixes:
__int__ returning non-int when underlying type is bool or of char type. #1334py::cpp_function::initialize was fixed. #3229pybind11::type_caster which require lifetime extension, such as for std::string_view. #3237Build system improvements:
Backend and tidying up:
std::string and std::string_view now avoids making an extra copy of the data on Python >= 3.3. #3257list, set, dict) such as (clear(), append(), insert(), etc...) and annotated them with py-non-const.clang-tidy-const-return and remove useless consts. #3254 #3194google-explicit-constructor option was enabled. #3250clang-tidy-readability rules to make boolean casts explicit improving code readability. Also enabled other misc and readability clang-tidy checks. #3148.pop() for list. #3116Minor missing functionality added:
Bug fixes:
.pop() for list. #3116Backend and tidying up:
New features:
py::implicitly_convertible<py::none, ...> for py::class_-wrapped types. #3059.char_() to type which gives the NumPy public char result, which also distinguishes types by bit length (unlike .kind()). #2864pybind11::bytearray to manipulate bytearray similar to bytes. #2799pybind11/stl/filesystem.h registers a type caster that, on C++17/Python 3.6+, converts std::filesystem::path to pathlib.Path and any os.PathLike to std::filesystem::path. #2730PYBIND11_VERSION_HEX define was added, similar to PY_VERSION_HEX. #3120Changes:
py::str changed to exclusively hold PyUnicodeObject. Previously py::str could also hold bytes, which is probably surprising, was never documented, and can mask bugs (e.g. accidental use of py::str instead of py::bytes). #2409object_api<>::operator() (e.g. py::function __call__). (This feature is available for Python 3.6+ only.) #2919self argument in calls to __init__(). #2914std::string_view if available to avoid a copy when passing an object to a std::ostream. #3042iostream.h documentation; attempts to make py::scoped_ostream_redirect thread safe have been removed, as it was only partially effective. #2995Fixes:
const T in pyarray_t. #3020simple_collector/unpacking_collector. #3013pybind11::builtin_exception is now explicitly exported, which means the types included/defined in different modules are identical, and exceptions raised in different modules can be caught correctly. The documentation was updated to explain that custom exceptions that are used across module boundaries need to be explicitly exported as well. #2999scoped_ostream_redirect. #2982setstate implementation will attempt to setattr __dict__ only if the unpickled dict object is not empty, to not force use of py::dynamic_attr() unnecessarily. #2972std::localtime. #2846weakref constructor from py::object to create a new weakref on conversion. #2832shared_ptr holder from a shared_from_this class. #2819RuntimeError when casting from py::str to std::string. #2903Build system improvements:
setup_helpers.py, test for platforms that have some multiprocessing features but lack semaphores, which ParallelCompile requires. #3043pybind11_INCLUDE_DIR in case CMAKE_INSTALL_INCLUDEDIR is absolute. #3005WITH_SOABI or WITHOUT_SOABI to CMake. #2938Pybind11Extension compilation flags with a Mingw64 python. #2921/MP (ignored flag). #2824pybind11.setup_helpers.intree_extensions can be used to generate Pybind11Extension instances from cpp files placed in the Python package source tree. #2831Backend and tidying up:
Werror to stricter Werror-all for Intel compiler and fixed minor issues. #2948_GLIBCXX_USE_CXX11_ABI. #2956pipx run pybind11 --include for a quick compile. #3117Minor missing functionality added:
.disarm for gil_scoped_acquire/gil_scoped_release. #2657Fixed or improved behavior in a few special cases:
object subclasses would not throw on being passed a Python object of the wrong type. #2701type_caster for integers does not convert Python objects with __int__ anymore with noconvert or during the first round of trying overloads. #2698__index__ is always called and not considered as conversion, consistent with Python 3.8+. #2801Build improvements:
extra_compile_args and extra_link_args automatically set by Pybind11Extension are now prepended, which allows them to be overridden by user-set extra_compile_args and extra_link_args. #2808--warn-uninitialized active. #2806STATIC / SHARED being ignored in FindPython mode. #2796CMAKE_CXX_VISIBILITY_PRESET if defined. #2793pybind11::embed. #2662Bug fixes:
scoped_ostream_redirect. #2675py::gil_scoped_acquire assert with CPython 3.9 debug build. #2683Warning fixes:
[-Wshadow-field-in-constructor-modified]. #2780__init__/__setstate__ in the tests. #2759Valgrind work:
__init__ on a non-pybind11 class instance. #2755Compiler support:
py::exec, py::eval, and py::eval_file now add the builtins module as "__builtins__" to their globals argument, better matching exec and eval in pure Python. #2616setup_helpers will no longer set a minimum macOS version higher than the current version. #2622def_buffer, cleaning up the capture object after the class_ object goes out of scope. #2634pybind11_INCLUDE_DIRS was incorrect, potentially causing a regression if it was expected to include PYTHON_INCLUDE_DIRS (please use targets instead). #2636py::enum_ constructor and methods, avoiding arg0 in the generated docstrings. #2637needs_recompile optional function to the ParallelCompiler helper, to allow a recompile to be skipped based on a user-defined function. #2643See upgrade-guide-2.6 for help upgrading to the new version.
New features:
py::kw_only(). #2100py::pos_only(). #2459py::is_final() class modifier to block subclassing (CPython only). #2151py::prepend(), allowing a function to be placed at the beginning of the overload chain. #1131py::type::of<T>() and py::type::of(h). #2364py::error_already_set::discard_as_unraisable(). #2372py::hash is now public. #2217py::class_<union_type> is now supported. Note that writing to one data member of the union and reading another (type punning) is UB in C++. Thus pybind11-bound enums should never be used for such conversions. #2320.Code correctness features:
__init__ is forgotten on subclasses. #2152py::bytes(o) when py::object o isn’t a bytes instance. #2349str fails. #2477API changes:
py::module was renamed py::module_ to avoid issues with C++20 when used unqualified, but an alias py::module is provided for backward compatibility. #2489py::module_ have been deprecated; please use pybind11::module_::create_extension_module if you were using the public constructor (fairly rare after PYBIND11_MODULE was introduced). #2552PYBIND11_OVERLOAD* macros and get_overload function replaced by correctly-named PYBIND11_OVERRIDE* and get_override, fixing inconsistencies in the presence of a closing ; in these macros. get_type_overload is deprecated. #2325Packaging / building improvements:
build-setuptools is easier thanks to a new pybind11.setup_helpers module, which provides utilities to use setuptools with pybind11. It can be used via PEP 518, setup_requires, or by directly importing or copying setup_helpers.py into your project.pybind11.get_cmake_dir() or python -m pybind11 --cmakedir to get the directory with the CMake configuration files, or include the site-packages location in your CMAKE_MODULE_PATH. Or you can use the new pybind11[global] extra when you install pybind11, which installs the CMake files and headers into your base environment in the standard location.pybind11-config is another way to write python -m pybind11 if you have your PATH set up.import pybind11 can now be type checked. #2588PYBIND11_CPP_STANDARD.PYTHON_EXECUTABLE is not set (venv, virtualenv, and conda) (similar to the new FindPython mode).CMAKE_INTERPROCEDURAL_OPTIMIZATION, set(CMAKE_CXX_VISIBILITY_PRESET hidden).CUDA as a language is now supported.pybind11_strip, pybind11_extension, pybind11_find_import added, see cmake/index.find-python-mode and nopython-mode with CMake. #2370pybind11_add_module() now accepts an optional OPT_SIZE flag that switches the binding target to size-based optimization if the global build type can not always be fixed to MinSizeRel (except in debug mode, where optimizations remain disabled). MinSizeRel or this flag reduces binary size quite substantially (~25% on some platforms). #2463Smaller or developer focused features and fixes:
mkdoc.py to a new repo, pybind11-mkdoc. There are no longer submodules in the main repo.py::memoryview segfault fix and update, with new py::memoryview::from_memory in Python 3, and documentation. #2223buffer_info on Python 2. #2503__eq__ defined but not __hash__, __hash__ is now set to None. #2291py::ellipsis now also works on Python 2. #2360std::tuple & std::pair supported in cast. #2334py::array now uses py::ssize_t as first argument type. #2293py::array. #2363unchecked_mutable_reference has access to operator () and [] when const. #2514py::vectorize is now supported on functions that return void. #1969py::capsule supports get_pointer and set_pointer. #1131py::len not clearing Python's error state when it fails and throws. #2575std::chrono::time_point now works when the resolution is not the same as the system. #2481py::array_t could accept arrays that did not match the requested ordering. #2484py::arg::none() is now also respected when passing keyword arguments. #2611pybind11/__init__.py and installation in setup.py. This fixes a number of open issues where pybind11 headers could not be found in certain environments. #1995.char8_t and u8string support. #2026.std::vector<...>::clear. #2074.py::buffer. #1466.new and delete. #1988, 759221.__await__, __aiter__, and __anext__ protocols. #1842.pybind11_add_module(): don't strip symbols when compiling in RelWithDebInfo mode. #1980.enum_: Reproduce Python behavior when comparing against invalid values (e.g. None, strings, etc.). Add back support for __invert__(). #1912, #1907.py::list. Added .empty() to all collection types. Added py::set::contains() and py::dict::contains(). #1887, #1884, #1888.py::details::overload_cast_impl is available in C++11 mode, can be used like overload_cast with an additional set of parentheses. #1581.get_include() on Conda. #1877.stl_bind.h: negative indexing support. #1882.Significantly reduced module binary size (10-20%) when compiled in C++11 mode with GCC/Clang, or in any mode with MSVC. Function signatures are now always precomputed at compile time (this was previously only available in C++14 mode for non-MSVC compilers). #934.
Add basic support for tag-based static polymorphism, where classes provide a method to returns the desired type of an instance. #1326.
Python type wrappers (py::handle, py::object, etc.) now support map Python's number protocol onto C++ arithmetic operators such as operator+, operator/=, etc. #1511.
A number of improvements related to enumerations:
- The
enum_implementation was rewritten from scratch to reduce code bloat. Rather than instantiating a full implementation for each enumeration, most code is now contained in a generic base class. #1511.- The
value()method ofpy::enum_now accepts an optional docstring that will be shown in the documentation of the associated enumeration. #1160.- check for already existing enum value and throw an error if present. #1453.
Support for over-aligned type allocation via C++17's aligned new statement. #1582.
Added py::ellipsis() method for slicing of multidimensional NumPy arrays #1502.
Numerous Improvements to the mkdoc.py script for extracting documentation from C++ header files. #1788.
pybind11_add_module(): allow including Python as a SYSTEM include path. #1416.
pybind11/stl.h does not convert strings to vector<string> anymore. #1258.
Mark static methods as such to fix auto-generated Sphinx documentation. #1732.
Re-throw forced unwind exceptions (e.g. during pthread termination). #1208.
Added __contains__ method to the bindings of maps (std::map, std::unordered_map). #1767.
Improvements to gil_scoped_acquire. #1211.
Type caster support for std::deque<T>. #1609.
Support for std::unique_ptr holders, whose deleters differ between a base and derived class. #1353.
Construction of STL array/vector-like data structures from iterators. Added an extend() operation. #1709,
CMake build system improvements for projects that include non-C++ files (e.g. plain C, CUDA) in pybind11_add_module et al. #1678.
Fixed asynchronous invocation and deallocation of Python functions wrapped in std::function. #1595.
Fixes regarding return value policy propagation in STL type casters. #1603.
Fixed scoped enum comparisons. #1571.
Fixed iostream redirection for code that releases the GIL. #1368,
Py_DEBUG define when compiling against a debug Python build. #1438.std::addressof to obtain holder address instead of operator&. #1435.extend() from a list or generator. #1496.pip internals (the recently released pip 10 has restricted access to this API). #1190.LICENSE into CONTRIBUTING.md: the licensing of contributions is not actually part of the software license as distributed. This isn't meant to be a substantial change in the licensing of the project, but addresses concerns that the clause made the license non-standard. #1109.__qualname__ generation, and in turn, fixes how class names (especially nested class names) are shown in generated docstrings. #1171.-Wdeprecated turned on, and add -Wdeprecated to the test suite compilation flags. #1191.setup.py. #1213.py::args argument for functions with both fixed positional and py::args arguments. #1216.py::args/py::kwargs arguments with overloaded functions. #1223.del map[item] for a stl_bind.h bound stl map. #1229.std::initializer_list<T> argument. #1249.py::module_::reload() member function for reloading a module. #1040.std::vector<bool> caster would fail to compile. The same fix also applies to any container which returns element proxies instead of references. #1053.py::keep_alive policy could not be applied to constructors. #1065.py::module_local type that's only registered in an external module. #1058.py::object. #1076.name in PYBIND11_MODULE(name, variable) can now be a macro. #1082.py::pickle() check for matching get and set types. #1064.<pybind11/stl.h>). #1077.Support for embedding the Python interpreter. See the documentation page </advanced/embedding> for a full overview of the new features. #774, #889, #892, #920.
#include <pybind11/embed.h> namespace py = pybind11; int main() { py::scoped_interpreter guard{}; // start the interpreter and keep it alive py::print("Hello, World!"); // use the Python API }
Support for inheriting from multiple C++ bases in Python. #693.
from cpp_module import CppBase1, CppBase2 class PyDerived(CppBase1, CppBase2): def __init__(self): CppBase1.__init__(self) # C++ bases must be initialized explicitly CppBase2.__init__(self)
PYBIND11_MODULE is now the preferred way to create module entry points. PYBIND11_PLUGIN is deprecated. See macros for details. #879.
// new PYBIND11_MODULE(example, m) { m.def("add", [](int a, int b) { return a + b; }); } // old PYBIND11_PLUGIN(example) { py::module m("example"); m.def("add", [](int a, int b) { return a + b; }); return m.ptr(); }
pybind11's headers and build system now more strictly enforce hidden symbol visibility for extension modules. This should be seamless for most users, but see the upgrade if you use a custom build system. #995.
Support for py::module_local types which allow multiple modules to export the same C++ types without conflicts. This is useful for opaque types like std::vector<int>. py::bind_vector and py::bind_map now default to py::module_local if their elements are builtins or local types. See module_local for details. #949, #981, #995, #997.
Custom constructors can now be added very easily using lambdas or factory functions which return a class instance by value, pointer or holder. This supersedes the old placement-new __init__ technique. See custom_constructors for details. #805, #1014.
struct Example { Example(std::string); }; py::class_<Example>(m, "Example") .def(py::init<std::string>()) // existing constructor .def(py::init([](int n) { // custom constructor return std::make_unique<Example>(std::to_string(n)); }));
Similarly to custom constructors, pickling support functions are now bound using the py::pickle() adaptor which improves type safety. See the upgrade and pickling for details. #1038.
Builtin support for converting C++17 standard library types and general conversion improvements:
std::variant is supported right out of the box. C++11/14 equivalents (e.g. boost::variant) can also be added with a simple user-defined specialization. See cpp17_container_casters for details. #811, #845, #989.std::string_view. #906.optional converter. #874.bool converter now accepts numpy.bool_ and types which define __bool__ (Python 3.x) or __nonzero__ (Python 2.7). #925.bytes to std::string/char* conversion on Python 3. #817.Scope guard call policy for RAII types, e.g. py::call_guard<py::gil_scoped_release>(), py::call_guard<py::scoped_ostream_redirect>(). See call_policies for details. #740.
Utility for redirecting C++ streams to Python (e.g. std::cout -> sys.stdout). Scope guard py::scoped_ostream_redirect in C++ and a context manager in Python. See ostream_redirect. #1009.
Improved handling of types and exceptions across module boundaries. #915, #951, #995.
Fixed destruction order of py::keep_alive nurse/patient objects in reference cycles. #856.
NumPy and buffer protocol related improvements:
static_cast. #782.std::complex and arrays inside PYBIND11_NUMPY_DTYPE. #831, #832.py::buffer_info and py::arrays using arbitrary containers or iterators instead of requiring a std::vector. #788, #822, #860.Support for allowing/prohibiting None for specific arguments and improved None overload resolution order. See none_arguments for details. #843. #859.
Added py::exec() as a shortcut for py::eval<py::eval_statements>() and support for C++11 raw string literals as input. See eval. #766, #827.
py::vectorize() ignores non-vectorizable arguments and supports member functions. #762.
Support for bound methods as callbacks (pybind11/functional.h). #815.
Allow aliasing pybind11 methods: cls.attr("foo") = cls.attr("bar"). #802.
Don't allow mixed static/non-static overloads. #804.
Fixed overriding static properties in derived classes. #784.
Added support for write only properties. #1144.
Improved deduction of member functions of a derived class when its bases aren't registered with pybind11. #855.
struct Base { int foo() { return 42; } } struct Derived : Base {} // Now works, but previously required also binding `Base` py::class_<Derived>(m, "Derived") .def("foo", &Derived::foo); // function is actually from `Base`
The implementation of py::init<> now uses C++11 brace initialization syntax to construct instances, which permits binding implicit constructors of aggregate types. #1015.
struct Aggregate { int a; std::string b; }; py::class_<Aggregate>(m, "Aggregate") .def(py::init<int, const std::string &>());
Fixed issues with multiple inheritance with offset base/derived pointers. #812, #866, #960.
Fixed reference leak of type objects. #1030.
Improved support for the /std:c++14 and /std:c++latest modes on MSVC 2017. #841, #999.
Fixed detection of private operator new on MSVC. #893, #918.
Intel C++ compiler compatibility fixes. #937.
Fixed implicit conversion of py::enum_ to integer types on Python 2.7. #821.
Added py::hash to fetch the hash value of Python objects, and .def(hash(py::self)) to provide the C++ std::hash as the Python __hash__ method. #1034.
Fixed __truediv__ on Python 2 and __itruediv__ on Python 3. #867.
py::capsule objects now support the name attribute. This is useful for interfacing with scipy.LowLevelCallable. #902.
Fixed py::make_iterator's __next__() for past-the-end calls. #897.
Added error_already_set::matches() for checking Python exceptions. #772.
Deprecated py::error_already_set::clear(). It's no longer needed following a simplification of the py::error_already_set class. #954.
Deprecated py::handle::operator==() in favor of py::handle::is() #825.
Deprecated py::object::borrowed/py::object::stolen. Use py::object::borrowed_t{}/py::object::stolen_t{} instead. #771.
Changed internal data structure versioning to avoid conflicts between modules compiled with different revisions of pybind11. #1012.
Additional compile-time and run-time error checking and more informative messages. #786, #794, #803.
Various minor improvements and fixes. #764, #791, #795, #840, #844, #846, #849, #858, #862, #871, #872, #881, #888, #899, #928, #931, #944, #950, #952, #962, #965, #970, #978, #979, #986, #1020, #1027, #1037.
Testing improvements. #798, #882, #898, #900, #921, #923, #963.
noconvert() syntax can be used to completely disable implicit conversions for specific arguments. #643, #634, #650.py::metaclass attribute is no longer necessary (and deprecated as of this release) when binding classes with static properties. #679,pybind11 can now use custom metaclasses. #679,py::args and py::kwargs can now be mixed with other positional arguments when binding functions using pybind11. #611.py::vectorize now works for any full-size group of C or F-contiguous arrays. The non-fast path is also faster since it no longer performs copies of the input arguments (except when type conversions are necessary). #610.operator new and operator delete implementations. #755.nullptr to None conversion fixed in various builtin type casters. #732.enum_ now exposes its members via a special __members__ attribute. #666.std::vector bindings created using stl_bind.h can now optionally implement the buffer protocol. #488.py::capsule API. Can be used to implement cleanup callbacks that are involved at module destruction time. #752.The pybind11 developers are excited to issue a release candidate of pybind11 with a subsequent v2.0.0 release planned in early January next year.
An incredible amount of effort by went into pybind11 over the last ~5 months, leading to a release that is jam-packed with exciting new features and numerous usability improvements. The following list links PRs or individual commits whenever applicable.
Happy Christmas!
Support for binding C++ class hierarchies that make use of multiple inheritance. #410.
PyPy support: pybind11 now supports nightly builds of PyPy and will interoperate with the future 5.7 release. No code changes are necessary, everything “just” works as usual. Note that we only target the Python 2.7 branch for now; support for 3.x will be added once its cpyext extension support catches up. A few minor features remain unsupported for the time being (notably dynamic attributes in custom types). #527.
Significant work on the documentation -- in particular, the monolithic advanced.rst file was restructured into a easier to read hierarchical organization. #448.
Many NumPy-related improvements:
Object-oriented API to access and modify NumPy ndarray instances, replicating much of the corresponding NumPy C API functionality. #402.
NumPy array dtype array descriptors are now first-class citizens and are exposed via a new class py::dtype.
Structured dtypes can be registered using the PYBIND11_NUMPY_DTYPE() macro. Special array constructors accepting dtype objects were also added.
One potential caveat involving this change: format descriptor strings should now be accessed via format_descriptor::format() (however, for compatibility purposes, the old syntax format_descriptor::value will still work for non-structured data types). #308.
Further improvements to support structured dtypes throughout the system. #472, #474, #459, #453, #452, and #505.
Fast access operators. #497.
Constructors for arrays whose storage is owned by another object. #440.
Added constructors for array and array_t explicitly accepting shape and strides; if strides are not provided, they are deduced assuming C-contiguity. Also added simplified constructors for 1-dimensional case.
Added buffer/NumPy support for char[N] and std::array<char, N> types.
Added memoryview wrapper type which is constructible from buffer_info.
Eigen: many additional conversions and support for non-contiguous arrays/slices. #427, #315, #316, #312, and #267
Incompatible changes in class_<...>::class_():
Declarations of types that provide access via the buffer protocol must now include the
py::buffer_protocol()annotation as an argument to theclass_constructor.Declarations of types that require a custom metaclass (i.e. all classes which include static properties via commands such as
def_readwrite_static()) must now include thepy::metaclass()annotation as an argument to theclass_constructor.These two changes were necessary to make type definitions in pybind11 future-proof, and to support PyPy via its cpyext mechanism. #527.
This version of pybind11 uses a redesigned mechanism for instantiating trampoline classes that are used to override virtual methods from within Python. This led to the following user-visible syntax change: instead of
py::class_<TrampolineClass>("MyClass") .alias<MyClass>() ....write
py::class_<MyClass, TrampolineClass>("MyClass") ....Importantly, both the original and the trampoline class are now specified as an arguments (in arbitrary order) to the
py::class_template, and thealias<..>()call is gone. The new scheme has zero overhead in cases when Python doesn't override any functions of the underlying C++ class. rev. 86d825.
Added eval and eval_file functions for evaluating expressions and statements from a string or file. rev. 0d3fc3.
pybind11 can now create types with a modifiable dictionary. #437 and #444.
Support for translation of arbitrary C++ exceptions to Python counterparts. #296 and #273.
Report full backtraces through mixed C++/Python code, better reporting for import errors, fixed GIL management in exception processing. #537, #494, rev. e72d95, and rev. 099d6e.
Support for bit-level operations, comparisons, and serialization of C++ enumerations. #503, #508, #380, #309. #311.
The class_ constructor now accepts its template arguments in any order. #385.
Attribute and item accessors now have a more complete interface which makes it possible to chain attributes as in obj.attr("a")[key].attr("b").attr("method")(1, 2, 3). #425.
Major redesign of the default and conversion constructors in pytypes.h. #464.
Added built-in support for std::shared_ptr holder type. It is no longer necessary to to include a declaration of the form PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>) (though continuing to do so won't cause an error). #454.
New py::overload_cast casting operator to select among multiple possible overloads of a function. An example:
py::class_<Pet>(m, "Pet") .def("set", py::overload_cast<int>(&Pet::set), "Set the pet's age") .def("set", py::overload_cast<const std::string &>(&Pet::set), "Set the pet's name");
This feature only works on C++14-capable compilers. #541.
C++ types are automatically cast to Python types, e.g. when assigning them as an attribute. For instance, the following is now legal:
py::module m = /* ... */ m.attr("constant") = 123;
(Previously, a py::cast call was necessary to avoid a compilation error.) #551.
Redesigned pytest-based test suite. #321.
Instance tracking to detect reference leaks in test suite. #324
pybind11 can now distinguish between multiple different instances that are located at the same memory address, but which have different types. #329.
Generalized unpacking API to permit calling Python functions from C++ using notation such as foo(a1, a2, *args, "ka"_a=1, "kb"_a=2, **kwargs). #372.
py::print() function whose behavior matches that of the native Python print() function. #372.
Added py::dict keyword constructor:auto d = dict("number"_a=42, "name"_a="World");. #372.
Added py::str::format() method and _s literal: py::str s = "1 + 2 = {}"_s.format(3);. #372.
Added py::repr() function which is equivalent to Python's builtin repr(). #333.
Improved construction and destruction logic for holder types. It is now possible to reference instances with smart pointer holder types without constructing the holder if desired. The PYBIND11_DECLARE_HOLDER_TYPE macro now accepts an optional second parameter to indicate whether the holder type uses intrusive reference counting. #533 and #561.
Mapping a stateless C++ function to Python and back is now “for free” (i.e. no extra indirections or argument conversion overheads). rev. 954b79.
Bindings for std::valarray<T>. #545.
Improved support for C++17 capable compilers. #562.
Bindings for std::optional<t>. #475, #476, #479, #499, and #501.
stl_bind.h: general improvements and support for std::map and std::unordered_map. #490, #282, #235.
The std::tuple, std::pair, std::list, and std::vector type casters now accept any Python sequence type as input. rev. 107285.
Improved CMake Python detection on multi-architecture Linux. #532.
Infrastructure to selectively disable or enable parts of the automatically generated docstrings. #486.
reference and reference_internal are now the default return value properties for static and non-static properties, respectively. #473. (the previous defaults were automatic). #473.
Support for std::unique_ptr with non-default deleters or no deleter at all (py::nodelete). #384.
Deprecated handle::call() method. The new syntax to call Python functions is simply handle(). It can also be invoked explicitly via handle::operator<X>(), where X is an optional return value policy.
Print more informative error messages when make_tuple() or cast() fail. #262.
Creation of holder types for classes deriving from std::enable_shared_from_this<> now also works for const values. #260.
make_iterator() improvements for better compatibility with various types (now uses prefix increment operator); it now also accepts iterators with different begin/end types as long as they are equality comparable. #247.
arg() now accepts a wider range of argument types for default values. #244.
Support keep_alive where the nurse object may be None. #341.
Added constructors for str and bytes from zero-terminated char pointers, and from char pointers and length. Added constructors for str from bytes and for bytes from str, which will perform UTF-8 decoding/encoding as required.
Many other improvements of library internals without user-visible changes
pybind11_add_module function to parent projects.std::vector<> type bindings analogous to Boost.Python's indexing_suiteeigen.h)ExtraFlags template argument to the NumPy array_t<> wrapper to disable an enforced cast that may lose precision, e.g. to create overloads for different precisions and complex vs real-valued matrices.class_ twiceNone value into a C++ lvalue referenceenum_::operator== that was triggered by the help() commandstr type to also work with bytes instances"name"_a user defined string literal that is equivalent to py::arg("name").py::arg, the test that verifies the number of arguments now runs at compile time.[[noreturn]] attribute to pybind11_fail() to quench some compiler warningsPYBIND11_OVERLOAD_NAME and PYBIND11_OVERLOAD_PURE_NAME macros which can be used to override virtual methods whose name differs in C++ and Python (e.g. __call__ and operator())iterator and make_iterator() improvements__bool__ on Python 2.x and Python 3.xpybind11::args and pybind11::kwargs types to create functions which take an arbitrary number of arguments and keyword arguments*args and *kwargsdef_property_* now correctly process docstring arguments (these formerly caused a segmentation fault)mkdoc.py improvements (enumerations, template arguments, DOC() macro accepts more arguments)keep_alive, macro usage)move return value policy that triggers C++11 move semantics. The automatic return value policy falls back to this case whenever a rvalue reference is encounteredPyGILState_Ensure and PyGILState_Release API[const] void *keep_alive fix: don't fail when there is no patientfunctional.h: acquire the GIL before calling a Python functionnone and iterable*args and *kwargs pass-through parameters to pybind11.get_include() functionmake_iterator() which turns a range indicated by a pair of C++ iterators into a iterable Python objectlen() and a variadic make_tuple() functionget_include() function to the Python module that returns the path of the directory containing the installed pybind11 header filesstd::reference_wrapper<>std::wstring and wchar_tnullptr-valued stringsvoid * pointers using capsulesstd::unique_ptr<>pybind11::vectorizearg::operator=() failskeep_alive call policy analogous to Boost.Python's with_custodian_and_wardpybind11::base<> attribute to indicate a subclass relationshippytypes.hbytes RAII type wrapper (maps to string in Python 2.7)__pybind11__ attributes on the Python side---they are now stored in a C++ hash table that is not visible in Pythonpybind11::vectorizeclass_ and cpp_functionoffsetof()std::array<> conversionsstd::shared_ptr<> conversionsstd::set<> conversions