Konstantin Bespalov
How to implement convenient Python bindings to C++
#1about 4 minutes
The business case for Python bindings to a C++ library
A C++ financial pricing library required a Python interface for quantitative analysts to perform research and development.
#2about 2 minutes
Evaluating an initial approach using .NET integration
The first attempt used a .NET assembly with pythonnet, but it suffered from poor performance and a lack of IDE support.
#3about 4 minutes
Choosing pybind11 for direct C++ to Python bindings
Pybind11 was selected over the Python/C API for its ability to minimize boilerplate code when creating direct C++ bindings.
#4about 2 minutes
Identifying usability gaps in the initial pybind11 bindings
The initial pybind11 implementation still lacked crucial features like type hints, Pythonic collections, and pickling support for multiprocessing.
#5about 2 minutes
Adding IDE support and type hints with stub files
PEP 484 and .pyi stub files provide a type interface for the C++ extension module, enabling autocompletion and navigation in IDEs.
#6about 2 minutes
Creating a Pythonic API with variants and magic methods
Using std::variant simplifies function arguments and implementing magic methods like __iter__ makes C++ collections behave like native Python ones.
#7about 1 minute
Enabling multiprocessing with custom pickling support
The copy_reg module is used to register custom serialization and deserialization functions, making C++ objects picklable for multiprocessing.
#8about 1 minute
Summarizing the solution and using code generation
The final solution combines pybind11 with several enhancements, and a code generator is recommended to maintain the bindings for large projects.
#9about 2 minutes
Q&A on exceptions, SWIG, and code generation tooling
The speaker answers audience questions about propagating C++ exceptions, comparing pybind11 to SWIG, and the specific code generator used.
Related jobs
Jobs that call for the skills explored in this talk.
envelio
Köln, Germany
Remote
Senior
Python
Software Architecture
Matching moments
06:51 MIN
Balancing business, technology, and people for holistic success
The Future of HR Lies in AND – Not in OR
06:10 MIN
Understanding global differences in work culture and motivation
The Future of HR Lies in AND – Not in OR
05:10 MIN
How the HR function has evolved over three decades
The Future of HR Lies in AND – Not in OR
03:13 MIN
How AI can create more human moments in HR
The Future of HR Lies in AND – Not in OR
06:59 MIN
Moving from 'or' to 'and' thinking in HR strategy
The Future of HR Lies in AND – Not in OR
06:04 MIN
The importance of a fighting spirit to avoid complacency
The Future of HR Lies in AND – Not in OR
03:28 MIN
Shifting from talent acquisition to talent architecture
The Future of HR Lies in AND – Not in OR
04:22 MIN
Navigating ambiguity as a core HR competency
The Future of HR Lies in AND – Not in OR
Featured Partners
Related Videos
CUDA in Python
Andy Terrel
C++ in constrained environments
Bjarne Stroustrup
101 brilliant things of C++
Andreas Fertig
Python: Behind the Scenes
Diana Gastrin
The best of both worlds: Combining Python and Kotlin for Machine Learning
Nils Kasseckert
Python-Based Data Streaming Pipelines Within Minutes
Bobur Umurzokov
Designing gRPC APIs - The things they don't tell you
Bastian Eicher
Accelerating Python on GPUs
Paul Graham
Related Articles
View all articles



From learning to earning
Jobs that call for the skills explored in this talk.

SOURCE GmbH
Wiesbaden, Germany
€65-75K
Senior
Python

NextGen Staffing
Charing Cross, United Kingdom
Remote
£35-40K
Intermediate
C
C++
JIRA
+3

N.P.A.
Charing Cross, United Kingdom
£85-120K
Senior
C++
JIRA
Linux
Python
+2

Capital Group
Paris, France
Intermediate
C++
Python
Pandas
Machine Learning
Amazon Web Services (AWS)

Autobrains AI Technologies GmbH
Berlin, Germany
Intermediate
C++
Python
Docker
Jenkins
Continuous Integration

IKB Deutsche Industriebank AG
Düsseldorf, Germany
Remote
GIT
JIRA
Azure
Python
+2

NextGen Staffing
Charing Cross, United Kingdom
Remote
£35-40K
Senior
C
C++
JIRA
+3

Clerkenwell
Charing Cross, United Kingdom
Senior
R
Python
Grafana
Data analysis
Machine Learning

Brunel GmbH
Bremen, Germany
C++
Python
Unit Testing
Software Architecture