GithubHelp home page GithubHelp logo

pyczmq's Introduction

Pyczmq

Pyczmq is a Python wrapper around the CZMQ zeromq bindings.

Build Status

Overview

Pyczmq exposes CZMQ functions via the cffi library's ABI access mode. No compiler is required to use it. The czmq library is accessed with dlopen and a set of parsed function declarations.

This is still a work in progress, not all of the API is fully wrapped yet. Most of the core context, socket, socket option, polling, beacon, auth, and cert functions are provided. Some functions will probably not be wrapped, notably those that provide duplicate functionality to built-in python type or libraries like zlist, zhash, zsys, zclock, zdir, etc.

Building and Installing

There are two methods for installing pyczmq.

Option 1 - Use the Cheese Shop

This is the easiest option for most users. If you have all the dependencies then it is as simple as:

[sudo] pip install pyczmq

NOTE: This version may not be as up to date as the Github master.

Option 2 - Use Github

This option would typically be used by users and contributing developers who want access to the most up to date version.

Dependencies

On Ubuntu you need the following packages (Other OSes may use a different package name) which are typicall installed using 'sudo apt-get install package':

libffi-dev
python-dev
python-virtualenv

The following Python packages are required which are typically installed using 'sudo pip install package':

cffi
nose

Libsodium provides security for ZMQ:

git clone git://github.com/jedisct1/libsodium.git
cd libsodium
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
cd ..

The ZMQ core library:

git clone git://github.com/zeromq/libzmq.git
cd libzmq
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
cd ..

The high-level CZMQ library:

git clone git://github.com/zeromq/czmq.git
cd czmq
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
cd ..

Pyczmq Installation

git clone git://github.com/zeromq/pyczmq.git
cd pyczmq
sudo python setup.py install

Testing

The pyczmq tests are run using the nose testing package. The tests are run from the top level pyczmq directory using:

nosetests [-v]

To report an issue, use the Pyczmq issue tracker at github.com.

Details

All CZMQ functions can be accessed directly via the low-level cffi binding, ie:

  • pyczmq.C.zctx_new

  • pyczmq.C.zsocket_bind

  • pyczmq.C.zstr_send

  • etc...

Functions also have aliases in a module level namespace interface, so:

  • pyczmq.C.zctx_new is pyczmq.zctx.new (with caveat, see below)

  • pyczmq.C.zsocket_bind is pyczmq.zsocket.bind

  • pyczmq.C.zstr_send is pyczmq.zstr.send

  • etc...

For example a simple PUSH/PULL socket pipeline::

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, 'foo')
zsocket.poll(pull, 1)
assert zstr.recv_nowait(pull) == 'foo'

Some of the 'new' functions in the module namespaces (like pyczmq.zctx.new) are wrappers that plug into Python's garbage collector, so you typically never need to explicitly destroy objects if you use the namespace interface.

Therefore, pyczmq.zctx.new isn't really pyczmq.C.zmq_new, but the effect is exactly the same. If you use the "raw" C binding interface pyczmq.C.zctx_new, however, you must explicitly garbage collect your own resources by calling the coresponding destroy method (pyczmq.C.zctx_destroy, etc.).

Some 'new' functions do not do this wrapping behavior, because they are meant to be destroyed by czmq. zmsg objects for example are destroyed by zmsg_send, and zframe objects have their ownership taken over by various functions in zmsg and are destroyed when the msg is sent and destroyed. If you create these objects and don't in turn call the functions that destroy them, you must explicitly destroy them yourself with zmsg.destroy or zframe.destroy.

API Documentation

The documentation for this binding can be found at readthedocs:

http://pyczmq.readthedocs.org/

pyczmq's People

Contributors

claws avatar gward avatar hintjens avatar michelp avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.