Using Reflection to Generate C++ Python Bindings

By Callum Piper

Python bindings for C++ can be valuable tools for developers who wish to make C++ libraries available for use in Python. There are many reasons developers may wish to do this, including testing, prototyping, or performance.

One of the issues often faced when writing Python bindings for C++ is the need to write excessive amounts of boilerplate code to bridge the gap between the C++ types and interfaces and their Python equivalents. Some libraries make this easier than others, but there is always overhead.

One of the easier and more commonly used libraries is PyBind11. This talk will explore how you can use Reflection in C++ to generate some of the necessary boilerplate code required when using PyBind11. We will present real-world examples that can be compiled using the latest experimental versions of compilers that support Reflection, and we’ll also generate genuine, usable Python bindings. While these compilers are still under development, this will still highlight how the use of Reflection can simplify — and abstract away — the generation of some simple boilerplate code. We will also look at the limitations of such an approach and what we might aim for in the future.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.