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
01:46 MIN
Proposing new patterns for enterprise Python development
Enterprise Python: Software That Lives Long And Prosper
02:36 MIN
Accelerating language support with numba-cuda and nupack
CUDA in Python
05:29 MIN
Navigating language-specific binding challenges
How AWS Generates Polyglot Libraries Based on a Single TypeScript Codebase
10:18 MIN
A progressive approach to programming GPUs in Python
Accelerating Python on GPUs
03:29 MIN
Leveraging vernacular developers for faster innovation
Enterprise Python: Software That Lives Long And Prosper
06:38 MIN
Adopting a philosophy of configuration without configuration files
Automagic Configuration in Python
21:16 MIN
Overcoming challenges in automotive software deployment
Intelligent Data Selection for Continual Learning of AI Functions
02:31 MIN
Key benefits of using Python-native streaming frameworks
Python-Based Data Streaming Pipelines Within Minutes
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
C++ in constrained environments
Bjarne Stroustrup
C++ Features You Might Not Know
Jonathan Müller
Full Stack Web Apps With Nothing But Python
Eli Holderness
Related Articles
View all articles



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

Vertus Partners
Charing Cross, United Kingdom
£90-110K
Python
Microservices
Continuous Integration

Blockchain.com
Paris, France
Remote
Python
Blockchain
Unit Testing



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

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


Squarepoint Capital
Charing Cross, United Kingdom
Intermediate
API
C++
Python
PostgreSQL
Amazon Web Services (AWS)

FactSet Research Systems Inc.
Charing Cross, United Kingdom
Intermediate
API
Python
Heroku
TypeScript
Continuous Integration
+1