ZeroMQ integration with asyncio (PEP 3156).
- Implements asyncio event loop for ZeroMQ sockets via ZmqEventLoop.
- Implements installable policy for ZerMQ event loop (see Installing ZeroMQ event loop), required for ZeroMQ sockets layer.
- Provides ZmqTransport and ZmqProtocol
- Provides RPC Request-Reply Push-Pull and Publish-Subscribe patterns for remote calls.
pip3 install aiozmq
Also probably you want to use aiozmq.rpc.
RPC module is optional and requires msgpack. You can install msgpack-python by:
pip3 install msgpack-python
aiozmq can be executed by Python 3 only. The most Linux distributions uses pip3 for installing Python 3 libraries but maybe your system uses Python 3 by default. Than try just pip instead of pip3. The same issue may be for virtualenv, travis continuous integration system etc.
The project is hosted on GitHub
Please feel free to file an issue on bug tracker if you had found a bug or have some suggestion for library improvement.
The library uses Travis for Continious Integration.
At first you need to install aiozmq policy to use ZeroMQ socket layer:
import asyncio import aiozmq asyncio.set_event_loop_policy(aiozmq.ZmqEventLoopPolicy())
For details please take a look on Installing ZeroMQ event loop.
After that you probably would like to use RPC:
import aiozmq.rpc class ServerHandler(aiozmq.rpc.AttrHandler): @aiozmq.rpc.method def remote_func(self, a:int, b:int) -> int: return a + b @asyncio.coroutine def go(): server = yield from aiozmq.rpc.serve_rpc( ServerHandler(), bind='tcp://127.0.0.1:5555') client = yield from aiozmq.rpc.connect_rpc( connect='tcp://127.0.0.1:5555') ret = yield from client.rpc.remote_func(1, 2) assert 3 == ret server.close() client.close() asyncio.get_event_loop().run_until_complete(go())
To execute the example you need to install msgpack first.
Indices and tables¶
- aiozmq — Core API
- aiozmq.rpc — Remote Procedure Calls
- Examples of aiozmq usage