You could try Cython (http://cython.org/). I've had good luck with it in the
past when I needed to connect python to C. The advantage over ctypes or CFFI
is that there aren't any version mismatches between the installed version of
nng and the bindings that are supposed to connect to them; the output is just a
single extension module. The disadvantage is debugging; I would set
breakpoints using pdb in my python code, then run python under gdb. When the
the breakpoint was hit, I could move into gdb (I can't remember how I did it,
it's been a few years). That way I'd get really close to whatever was causing
the problem, and I could step into the actual code with gdb.
One thing to note though; you need to be careful about heap-allocated memory on
the C-side. If python thinks it owns it, it'll delete it out from under you,
and if it doesn't, it might not get cleaned up properly. Follow whatever
Cython recommends scrupulously, and you'll be fine.
Good luck!
Cem Karan
________________________________
From: nanomsg-bounce@xxxxxxxxxxxxx [nanomsg-bounce@xxxxxxxxxxxxx] on behalf of
Aby Louw [aby.github@xxxxxxxxx]
Sent: Thursday, February 15, 2018 7:11 AM
To: nanomsg@xxxxxxxxxxxxx
Subject: [Non-DoD Source] [nanomsg] nng Python wrappers
Hi,
I'm interested in using nng in Python in a project but it seems that there
aren't wrappers for Python yet. I have created a Python wrapper for a large
project in SWIG before and therefore started writing a wrapper using SWIG and
although it seems to be working, it feels very bulky with a lot of overhead in
the C code. I finished the basic library and made classes of nng_socket,
nng_msg, nng_dialer, nng_listener and nng_pipe. I started writing tests to
mirror those in nng but then I wondered if there aren't better solutions. I'm
also not so sure that I will be interested in using it for other interpreted
languages and that makes me wonder if the SWIG solution is worth pursuing.
What I would like some input on is what the community would think the best
approach would be and why? CFFI based like pyzmq, something simple like ctypes?
or maybe continue with SWIG with the possibility of extending it to other
interpreters?
Regards,
Aby