{"id":13481975,"url":"https://github.com/aio-libs/aiozmq","last_synced_at":"2025-03-27T12:31:52.275Z","repository":{"id":44164504,"uuid":"12610153","full_name":"aio-libs/aiozmq","owner":"aio-libs","description":"Asyncio (pep 3156) integration with ZeroMQ","archived":false,"fork":false,"pushed_at":"2022-11-10T21:59:23.000Z","size":1039,"stargazers_count":419,"open_issues_count":30,"forks_count":56,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-07-30T01:09:44.637Z","etag":null,"topics":["asyncio","zeromq","zmq"],"latest_commit_sha":null,"homepage":"aiozmq.readthedocs.org","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aio-libs.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-05T05:28:42.000Z","updated_at":"2024-07-28T19:37:36.000Z","dependencies_parsed_at":"2022-07-30T11:07:58.650Z","dependency_job_id":null,"html_url":"https://github.com/aio-libs/aiozmq","commit_stats":null,"previous_names":["aio-libs-abandoned/aiozmq"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiozmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiozmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiozmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiozmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aio-libs","download_url":"https://codeload.github.com/aio-libs/aiozmq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245845092,"owners_count":20681833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","zeromq","zmq"],"created_at":"2024-07-31T17:00:57.916Z","updated_at":"2025-03-27T12:31:51.964Z","avatar_url":"https://github.com/aio-libs.png","language":"Python","funding_links":[],"categories":["Python","消息队列","Message Queues"],"sub_categories":[],"readme":"asyncio integration with ZeroMQ\n===============================\n\nasyncio (PEP 3156) support for ZeroMQ.\n\n.. image:: https://travis-ci.com/aio-libs/aiozmq.svg?branch=master\n   :target: https://travis-ci.com/aio-libs/aiozmq\n\nThe difference between ``aiozmq`` and vanilla ``pyzmq`` (``zmq.asyncio``) is:\n\n``zmq.asyncio`` works only by replacing the *base event loop* with a custom one.\nThis approach works but has two disadvantages:\n\n1. ``zmq.asyncio.ZMQEventLoop`` cannot be combined with\n   other loop implementations (most notable is the ultra fast ``uvloop``).\n\n2. It uses the internal ZMQ Poller which has fast ZMQ Sockets support\n   but isn't intended to work fast with many (thousands) regular TCP sockets.\n\n   In practice it means that ``zmq.asyncio`` is not recommended to be used with\n   web servers like ``aiohttp``.\n\n   See also https://github.com/zeromq/pyzmq/issues/894\n\nDocumentation\n-------------\n\nSee http://aiozmq.readthedocs.org\n\nSimple high-level client-server RPC example:\n\n.. code-block:: python\n\n    import asyncio\n    import aiozmq.rpc\n\n\n    class ServerHandler(aiozmq.rpc.AttrHandler):\n\n        @aiozmq.rpc.method\n        def remote_func(self, a:int, b:int) -\u003e int:\n            return a + b\n\n\n    async def go():\n        server = await aiozmq.rpc.serve_rpc(\n            ServerHandler(), bind='tcp://127.0.0.1:5555')\n        client = await aiozmq.rpc.connect_rpc(\n            connect='tcp://127.0.0.1:5555')\n\n        ret = await client.call.remote_func(1, 2)\n        assert 3 == ret\n\n        server.close()\n        client.close()\n\n    asyncio.run(go())\n\nLow-level request-reply example:\n\n.. code-block:: python\n\n    import asyncio\n    import aiozmq\n    import zmq\n\n    async def go():\n        router = await aiozmq.create_zmq_stream(\n            zmq.ROUTER,\n            bind='tcp://127.0.0.1:*')\n\n        addr = list(router.transport.bindings())[0]\n        dealer = await aiozmq.create_zmq_stream(\n            zmq.DEALER,\n            connect=addr)\n\n        for i in range(10):\n            msg = (b'data', b'ask', str(i).encode('utf-8'))\n            dealer.write(msg)\n            data = await router.read()\n            router.write(data)\n            answer = await dealer.read()\n            print(answer)\n        dealer.close()\n        router.close()\n\n    asyncio.run(go())\n\n\nComparison to pyzmq\n-------------------\n\n``zmq.asyncio`` provides an *asyncio compatible loop* implementation.\n\nBut it's based on ``zmq.Poller`` which doesn't work well with massive\nnon-zmq socket usage.\n\nE.g. if you build a web server for handling at least thousands of\nparallel web requests (1000-5000) ``pyzmq``'s internal poller will be slow.\n\n``aiozmq`` works with epoll natively, it doesn't need a custom loop\nimplementation and cooperates pretty well with `uvloop` for example.\n\nFor details see https://github.com/zeromq/pyzmq/issues/894\n\n\nRequirements\n------------\n\n* Python_ 3.6+\n* pyzmq_ 13.1+\n* optional submodule ``aiozmq.rpc`` requires msgpack_ 0.5+\n\n\n\nLicense\n-------\n\naiozmq is offered under the BSD license.\n\n.. _python: https://www.python.org/\n.. _pyzmq: https://pypi.python.org/pypi/pyzmq\n.. _asyncio: https://pypi.python.org/pypi/asyncio\n.. _msgpack: https://pypi.python.org/pypi/msgpack\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faiozmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faio-libs%2Faiozmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faiozmq/lists"}