[zeromq-dev] CZMQ Python Bindings

Michel Pelletier pelletier.michel at gmail.com
Wed Oct 9 04:28:40 CEST 2013

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:


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')
    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,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20131008/9ca3c8ce/attachment.htm>

More information about the zeromq-dev mailing list