CppCon 2016: “Introduction to C++ python extensions and embedding Python in C++ Apps'

preview_player
Показать описание


C and C++ languages are the best for high performance, and probably have the largest quota among programming languages, implementing the backbone of all of the existing computing infrastructure, including those other programming languages. On the other hand, python usage is also very popular and growing, with its amazing simplicity, and it is being adopted as the generic language for learning and many other tasks ranging from BigData and systems to web sites. Python is also being widely used in development and systems automation “devops”, being the language of choice for many scripting tasks (build systems as SCons are written in python) or as glue between subsystems.

This talk will introduce how both C++ and Python languages can work together. As many of the methods to write python extensions typically use a raw C API, we’ll focus on how to use C++ in such extensions, and the C++ code itself.

First, I’ll briefly present the canonical python C API, and how different aspects of C++ (as Exceptions) have to be handled. Then, I will describe and compare a couple of pure C++ ways to build extensions: the reference Boost.Python and the modern, but very active and popular successor, Pybind11.

Finally, I will conclude explaining how to embed a python interpreter in a C++ application. This allows C++ programs to introduce a powerful and known language to let the users define extensions or configuration of our C++ application without requiring them to build anything.

All presented examples will be complete and working, with build scripts included, in a public repository.

Diego Rodriguez-Losada
SW Engineer, Freelance


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

18:04 That GIL lock seems like it should be before the PyCallable_Check, as PyCallable_Check can actually hit the interpreter (It will do a getattr for __call__)

reductor_
Автор

my kind request, if u can do a sample project in visual studio and show the demo for it, would be a grate help :)

snehasahu
Автор

Is it possible to have overloaded constructors with pybind11?

ilciavo
Автор

Python is more high level and closer to english, the cost is obviously performance...99% of the time it does not matter...if you know C++ you can further optimize your code so it runs as assembly

ViralKiller
Автор

If you know how to make this beast of wrapping, then you could just as well write the whole thing in C++20

johnnyserup
Автор

In 12:00 , Why you have wrap only the `friends` attribute and not the `happiness`? Do we have to only wrap STL stuffs and rest all attributes are managed by pybind11?

shibasispatel
Автор

As long as there is a GIL and reference counting (which makes it the slowest script language at the moment) it will be only used for simple small script stuff.

llothar
join shbcf.ru