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.
Matching moments
14:53 MIN
Accelerating language support with numba-cuda and nupack
CUDA in Python
13:40 MIN
Navigating language-specific binding challenges
How AWS Generates Polyglot Libraries Based on a Single TypeScript Codebase
28:27 MIN
A progressive approach to programming GPUs in Python
Accelerating Python on GPUs
36:33 MIN
Key benefits of using Python-native streaming frameworks
Python-Based Data Streaming Pipelines Within Minutes
05:50 MIN
Using NVIDIA libraries to easily accelerate applications
WWC24 - Ankit Patel - Unlocking the Future Breakthrough Application Performance and Capabilities with NVIDIA
17:37 MIN
A look at upcoming Python GPU programming tools
Accelerating Python on GPUs
05:50 MIN
Navigating the CUDA Python software ecosystem
Accelerating Python on GPUs
21:44 MIN
Integrating Web3 with existing Web2 stacks
Debunking the Top 10 Myths about Web 3
Featured Partners
Related Videos
CUDA in Python
Andy Terrel
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
101 brilliant things of C++
Andreas Fertig
Enjoying SQL data pipelines with dbt
Matthias Niehoff
C++ in constrained environments
Bjarne Stroustrup
Designing gRPC APIs - The things they don't tell you
Bastian Eicher
Related Articles
View all articles



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

Senior Python Software Entwickler (m/w/d) Google Cloud
SOURCE GmbH
Wiesbaden, Germany
€65-75K
Senior
Python

Software Developer with C++ , Python Financial
NextGen Staffing
Charing Cross, United Kingdom
Remote
€35-40K
Intermediate
C
C++
JIRA
+3

Python Software Engineer Data - Fintech
Client Server
Nottingham, United Kingdom
Remote
€90-100K
ETL
Azure
Spark
+7

Senior Software Engineer / Developer with C++ , Python Financial /Trade
NextGen Staffing
Charing Cross, United Kingdom
Remote
€35-40K
Senior
C
C++
JIRA
+3

Prototyping-Techniker (Softwareentwickler C++ & Python)
Qualitest Group
Zürich, Switzerland
QT
C++
Linux
NumPy
SciPy
+7

Python Softwareentwickler mit mathematisch-naturwissenschaftlichem Schwerpunkt
IKB Deutsche Industriebank AG
Düsseldorf, Germany
Remote
GIT
JIRA
Azure
Python
+2



Python Backend Engineer (Mathematical Focus)
Klepsydra Technologies
Santa Cruz de Tenerife, Spain
Remote
Bash
REST
Linux
NumPy
+2