Package: aiozmq
asyncio (PEP 3156) support for ZeroMQ.The difference betweenaiozmqand vanillapyzmq(zmq.asyncio) is:zmq.asyncioworks only by replacing thebase event loopwith a custom one.
This approach works but has two disadvantages:zmq.asyncio.ZMQEventLoopcannot be combined with
other loop implementations (most notable is the ultra fastuvloop).It uses the internal ZMQ Poller which has fast ZMQ Sockets support
but isn’t intended to work fast with many (thousands) regular TCP sockets.In practice it means thatzmq.asynciois not recommended to be used with
web servers likeaiohttp.See alsohttps://github.com/zeromq/pyzmq/issues/894DocumentationSeehttp://aiozmq.readthedocs.orgSimple high-level client-server RPC example:importasyncioimportaiozmq.rpcclassServerHandler(aiozmq.rpc.AttrHandler):@aiozmq.rpc.methoddefremote_func(self,a:int,b:int)->int:returna+basyncdefgo():server=awaitaiozmq.rpc.serve_rpc(ServerHandler(),bind='tcp://127.0.0.1:5555')client=awaitaiozmq.rpc.connect_rpc(connect='tcp://127.0.0.1:5555')ret=awaitclient.call.remote_func(1,2)assert3==retserver.close()client.close()asyncio.run(go())Low-level request-reply example:importasyncioimportaiozmqimportzmqasyncdefgo():router=awaitaiozmq.create_zmq_stream(zmq.ROUTER,bind='tcp://127.0.0.1:*')addr=list(router.transport.bindings())[0]dealer=awaitaiozmq.create_zmq_stream(zmq.DEALER,connect=addr)foriinrange(10):msg=(b'data',b'ask',str(i).encode('utf-8'))dealer.write(msg)data=awaitrouter.read()router.write(data)answer=awaitdealer.read()print(answer)dealer.close()router.close()asyncio.run(go())Comparison to pyzmqzmq.asyncioprovides anasyncio compatible loopimplementation.But it’s based onzmq.Pollerwhich doesn’t work well with massive
non-zmq socket usage.E.g. if you build a web server for handling at least thousands of
parallel web requests (1000-5000)pyzmq’s internal poller will be slow.aiozmqworks with epoll natively, it doesn’t need a custom loop
implementation and cooperates pretty well withuvloopfor example.For details seehttps://github.com/zeromq/pyzmq/issues/894RequirementsPython3.6+pyzmq13.1+optional submoduleaiozmq.rpcrequiresmsgpack0.5+Licenseaiozmq is offered under the BSD license.CHANGES1.0.0 (2022-11-02)Support Python 3.9, 3.10, and 3.11 (thanks in part to Esben Sonne)Drop support for Python 3.5Remove support for using annotations as conversion functions0.9.0 (2020-01-25)Support Python 3.7 and 3.80.8.0 (2016-12-07)Respectevents_backlogparameter in zmq stream creation #860.7.1 (2015-09-20)Fix monitoring events implementationMake the library compatible with Python 3.50.7.0 (2015-07-31)Implement monitoring ZMQ events #50Do deeper lookup for inhereted classes #54Relax endpont check #56Implement monitoring events for stream api #520.6.1 (2015-05-19)Dynamically get list of pyzmq socket types0.6.0 (2015-02-14)Process asyncio specific exceptions as builtins.Add repr(exception) to rpc server call logs if anyAdd transport.get_write_buffer_limits() methodAdd __repr__ to transportAdd zmq_type to tr.get_extra_info()Add zmq streams0.5.2 (2014-10-09)Poll events after sending zmq message for eventless transport0.5.1 (2014-09-27)Fix loopless transport implementation.0.5.0 (2014-08-23)Support zmq devices in aiozmq.rpc.serve_rpc()Add loopless 0MQ transport0.4.1 (2014-07-03)Add exclude_log_exceptions parameter to rpc servers.0.4.0 (2014-05-28)Implement pause_reading/resume_reading methods in ZmqTransport.0.3.0 (2014-05-17)Add limited support for Windows.Fix unstable test execution, change ZmqEventLoop to use global
shared zmq.Context by default.Process cancellation on rpc servers and clients.0.2.0 (2014-04-18)msg in msg_received now is a list, not tupleAllow to send empty msg by trsansport.write()Add benchmarksDerive ServiceClosedError from aiozmq.rpc.Error, not ExceptionImplement logging from remote calls at server side (log_exceptions parameter).Optimize byte counting in ZmqTransport.0.1.3 (2014-04-10)Function default values are not passed to an annotaion.
Add check for libzmq version (should be >= 3.0)0.1.2 (2014-04-01)Function default values are not passed to an annotaion.0.1.1 (2014-03-31)Rename plural module names to single ones.0.1.0 (2014-03-30)Implement ZmqEventLoop withcreate_zmq_connectionmethod which operates
on zmq transport and protocol.Implement ZmqEventLoopPolicy.Introduce ZmqTransport and ZmqProtocol.Implement zmq.rpc with RPC, PUSHPULL and PUBSUB protocols.