[zeromq-dev] CZMQ Python Bindings
Pieter Hintjens
ph at imatix.com
Wed Oct 9 09:27:56 CEST 2013
Hi Michel,
This is great fun! I'm going to look at what you did since I'd like to
try generating Python wrappers for our standardish C APIs (FileMQ,
Zyre, for instance).
-Pieter
On Wed, Oct 9, 2013 at 4:28 AM, Michel Pelletier
<pelletier.michel at gmail.com> wrote:
> Wanting to know more about Python and CFFI, I decided to do a
> straightforward wrap job for Python around the CZMQ C API. I have it
> reasonable complete enough to write some simple code and tests. I've pushed
> it up to github:
>
> https://github.com/michelp/pyczmq
>
> Most of the core functionality, zctx, zsocket, zsockopt, zpoller, zmsg,
> zframe, zstr, zloop, zbeacon, zcert, zauth, are exposed as both straight
> wrappers around the C interface as well as some namespaced functions that
> provide a high level functional interface (eg, turning cdata char * into
> python byte strings, etc). For example:
>
>
> ctx = zctx.new()
> push = zsocket.new(ctx, zsocket.PUSH)
> pull = zsocket.new(ctx, zsocket.PULL)
> zsocket.bind(push, 'inproc://test')
> zsocket.connect(pull, 'inproc://test')
> zstr.send(push, 'foo')
> assert zstr.recv(pull) == 'foo'
> zstr.send(push, 'bar')
> zsocket.poll(pull, 1)
> assert zstr.recv_nowait(pull) == 'bar'
>
>
>
> There's also a first stab at providing an OO interface in the form of
> Context, Socket, Beacon and Loop classes. Here's a working example:
>
> ctx = Context()
> pub = ctx.socket('PUB')
> sub = ctx.socket('SUB')
> sub.set_subscribe('')
> pub.bind('inproc://zoop')
> sub.connect('inproc://zoop')
> pub.send('foo')
> sub.poll(1)
> assert sub.recv() == 'foo'
>
>
> This is a work in progress, it's useful enough now to create socket and
> messages and send and receive data. I'd certainly love any form of help,
> just send me a pull request. Featured desired are way more tests! And of
> course any missing functions that need wrapping, or new functionality.
>
> Thanks and enjoy,
>
> -Michel
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
More information about the zeromq-dev
mailing list