World Congress 2023 • Aug 11, 2023

How to implement convenient Python bindings to C++

Konstantin Bespalov

Integrating strict C++ into Python doesn't have to be sluggish. Master pybind11 to achieve zero-copy NumPy integrations and seamless type hinting. Build high-performance, idiomatic backtesting pipelines.

Pause
Mute Enter Fullscreen
#1 about 4 min

Overview of the derivative pricing library architecture

The context and architecture of a C++ analytical library for pricing foreign exchange derivatives.

#2 about 3 min

Initial bindings using pythonnet and their limitations

Why wrapping a dotnet assembly with pythonnet resulted in poor performance and missing type hints.

#3 about 3 min

Evaluating pybind11 against direct Python C API

How pybind11 reduces boilerplate compared to the native Python C API while supporting function overloading and buffers.

#4 about 2 min

Defining classes and building packages with pybind11

A walkthrough of exposing C++ classes to Python and compiling the extension module.

#5 about 5 min

Adding IDE type hints using stub files

Implementing PEP 484 stub files to enable autocomplete and static type checking in editors.

#6 about 2 min

Simplifying interfaces with C++ variant types

Using variant types and mapping functions to accept simple Python datatypes instead of custom wrapped objects.

#7 about 1 min

Implementing magic methods for Python collections

Enabling native collection behaviors like iteration and membership testing by adding magic methods.

#8 about 2 min

Supporting multiprocessing with custom copyreg pickling

Registering serialization functions via the copyreg module to make C++ objects picklable for multiprocessing.

#9 about 4 min

Summary of Python bindings and audience QA

A review of the pybind11 implementation steps and answers to audience questions on Python extension methodologies.

Matching moments

1:11 min

The expanded CUDA ecosystem and native Python support

Paul Graham Paul Graham · World Congress 2026 Europe

3:52 min

Bridging Fortran and Python in modern computing

Stephen Jones · Coffee With Developers

1:46 min

Bridging Python prototyping environments and embedded systems languages

Nico Schmidt · LIVE

1:32 min

Evaluating absolute performance thresholds between Python and procedural syntaxes

Paul Graham Paul Graham · LIVE

4:37 min

Simplifying parallel programming with the CUDA ecosystem

Paul Graham Paul Graham · LIVE

1:24 min

Bridging dynamic typing paradigms for Python cross-language libraries

Markus Ziller Markus Ziller · World Congress 2024