Python, C++ interaction

Joshua Landau joshua at landau.ws
Wed Dec 3 08:35:39 EST 2014


On 3 December 2014 at 08:29, Michael Kreim <michael at perfect-kreim.de> wrote:
>
> What are you using to wrap C++ classes for Python?
> Can you recommend swig? Should I give it another try?
> Did I misunderstood ctypes?

The PyPy guys would love it if you used CFFI. Cython is also a
wonderful approach. There's a lot of support of Cython, but it's also
possible to find comparisons in CFFI's favour:
http://eev.ee/blog/2013/09/13/cython-versus-cffi/

I've not actually used CFFI, but I've heard good things about it.

> Also later on in our code development we would like to pass python lambda
> functions to C++. So far I understood that this seems not to be possible. Do
> you have any ideas or hints on this topics?

This is definitely possible. You'll need to build C++ against CPython
and use the Python C API. I've personally found that Boost::Python
simplified this dramatically and IMHO if most of your code needs to
use Python types directly from C++ I'd scrap Cython altogether and
just use Boost.

Here's some stuff on callbacks with CFFI:
https://cffi.readthedocs.org/en/release-0.5/#callbacks



More information about the Python-list mailing list