So, let's talk about Python because
when you say Python, you probably think
for the first time, probably think
of some big, green,
massive, kick ass snake
that's going to bite off your head,
something like this.
This snake is fast and deadly.
It's very much like C++, but as you start
digging into the Python, you find out
that it's not so.
It's more like this.
(audience laughs)
Python is adorable, like really lovable
and very much like this sloth.
It's very slow.
You find out very fast.
By this time, you got very used to the,
this very high-level programming,
and you're used to that,
and you like it very much,
and you don't want to go back to the snake
because it's trying to bite your head off
with those big teeth.
What you actually are looking for
is something like this.
(audience laughs)
It would be nice to have a
C++ snakey back end,
and this adorable front
end that Python provides.
I think it's a very good picture.
I made it myself.
So that's when the
Pybind11 comes into place.
Pybind is a C++ library that provides
Python bindings of C++ code.
It's very easy to use,
exposes all the fancy types
you can define in C++.
It's very lightweight,
header-only, easy-to-use,
What's most important is that it exploits
the modern features of
C++11 and later standards
unlike the older version of Boost,
which gives bindings to
Python and this kinda stuff.
Let's see some examples because
that's what we want, right?
Here's an example of some C++ code.
It creates, we define
point, we define a function
that uses Mr. Graham's Convex Hull,
and Convex Hull Algorithm
and tries to compute it,
and then we define this
magic syntax down there
that says we are about to
define a Python module.
It's called unicorn_land
because we want unicorns,
and then we define a point,
we define its constructors,
we can see that it's very
easy to define constructors.
You just name the signature of the point,
and it just dusts its
magic, and then you say
it has some attributes like x and y,
and then you bind the
Convex Hull Algorithm,
and then you go to Python,
compile this thing,
import it to Python, like this.
It's very simple.
So here you can see I
created little HTTP server
that just has this Convex Hull endpoint,
and it accepts
points in JSON,
parses it, sends it to C++,
and computes it and sends it back.
It's very easy.
So that's what you can do with Pybind,
and another thing is that in Python,
you usually get problems with GIL,
the global interpretive lock,
because Python relies heavily on that.
You can help this.
You can make, actually,
Python truly parallel,
by using executors because you don't want
your asynchronous functions blocked,
and then in C++, when
you define your function,
you can release the GIL
if you are sure that
your resources are safe.
Release the GIL, and you
obtain the true parallelism,
like it's the holy grail,
probably, in Python.
There are loads and loads more features
that Pybind currently supports.
The maintainers are working very hard
to add more and more
stuff, and it's great.
That's about it.
You can find it on GitHub.
There's the link, and thank you very much.
If you have any questions,
just find me later.
(applause)
