{"id":13595289,"url":"https://github.com/mosquito/aio-pika","last_synced_at":"2026-02-21T20:09:55.716Z","repository":{"id":39635135,"uuid":"69458400","full_name":"mosquito/aio-pika","owner":"mosquito","description":"AMQP 0.9 client designed for asyncio and humans.","archived":false,"fork":false,"pushed_at":"2024-08-13T06:49:45.000Z","size":2057,"stargazers_count":1246,"open_issues_count":180,"forks_count":189,"subscribers_count":26,"default_branch":"master","last_synced_at":"2024-10-29T15:09:18.069Z","etag":null,"topics":["aiormq","amqp","amqp-connection","async-python","asyncio","mypy","python-3","python-3-6","python3-10","python3-11","python3-7","python3-8","python3-9","rabbitmq","typehints"],"latest_commit_sha":null,"homepage":"https://aio-pika.readthedocs.org/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mosquito.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-28T11:54:18.000Z","updated_at":"2024-10-27T15:47:07.000Z","dependencies_parsed_at":"2024-01-05T14:26:37.281Z","dependency_job_id":"773ab107-095c-4cac-b8a4-fe5747f741ae","html_url":"https://github.com/mosquito/aio-pika","commit_stats":{"total_commits":1065,"total_committers":121,"mean_commits":8.801652892561984,"dds":0.3352112676056338,"last_synced_commit":"eb5990e9919d0257088d268cd29bc49a1c7d4e87"},"previous_names":[],"tags_count":114,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosquito%2Faio-pika","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosquito%2Faio-pika/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosquito%2Faio-pika/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosquito%2Faio-pika/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mosquito","download_url":"https://codeload.github.com/mosquito/aio-pika/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043501,"owners_count":22004962,"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":["aiormq","amqp","amqp-connection","async-python","asyncio","mypy","python-3","python-3-6","python3-10","python3-11","python3-7","python3-8","python3-9","rabbitmq","typehints"],"created_at":"2024-08-01T16:01:47.148Z","updated_at":"2026-02-21T20:09:55.654Z","avatar_url":"https://github.com/mosquito.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":".. _documentation: https://docs.aio-pika.com/\n.. _adopted official RabbitMQ tutorial: https://docs.aio-pika.com/rabbitmq-tutorial/index.html\n\n\naio-pika\n========\n\n.. image:: https://coveralls.io/repos/github/mosquito/aio-pika/badge.svg?branch=master\n    :target: https://coveralls.io/github/mosquito/aio-pika\n    :alt: Coveralls\n\n.. image:: https://github.com/mosquito/aio-pika/workflows/tests/badge.svg\n    :target: https://github.com/mosquito/aio-pika/actions?query=workflow%3Atests\n    :alt: Github Actions\n\n.. image:: https://img.shields.io/pypi/v/aio-pika.svg\n    :target: https://pypi.python.org/pypi/aio-pika/\n    :alt: Latest Version\n\n.. image:: https://img.shields.io/pypi/wheel/aio-pika.svg\n    :target: https://pypi.python.org/pypi/aio-pika/\n\n.. image:: https://img.shields.io/pypi/pyversions/aio-pika.svg\n    :target: https://pypi.python.org/pypi/aio-pika/\n\n.. image:: https://img.shields.io/pypi/l/aio-pika.svg\n    :target: https://pypi.python.org/pypi/aio-pika/\n\n\nA wrapper around `aiormq`_ for asyncio and humans.\n\nCheck out the examples and the tutorial in the `documentation`_.\n\nIf you are a newcomer to RabbitMQ, please start with the `adopted official RabbitMQ tutorial`_.\n\n.. _aiormq: http://github.com/mosquito/aiormq/\n\n.. note::\n   Since version ``5.0.0`` this library doesn't use ``pika`` as AMQP connector.\n   Versions below ``5.0.0`` contains or requires ``pika``'s source code.\n\n.. note::\n   The version 7.0.0 has breaking API changes, see CHANGELOG.md\n   for migration hints.\n\n\nFeatures\n--------\n\n* Completely asynchronous API.\n* Object oriented API.\n* Transparent auto-reconnects with complete state recovery with `connect_robust`\n  (e.g. declared queues or exchanges, consuming state and bindings).\n* Python 3.7+ compatible.\n* For python 3.5 users, aio-pika is available via `aio-pika\u003c7`.\n* Transparent `publisher confirms`_ support.\n* `Transactions`_ support.\n* Complete type-hints coverage.\n\n\n.. _Transactions: https://www.rabbitmq.com/semantics.html\n.. _publisher confirms: https://www.rabbitmq.com/confirms.html\n\n\nInstallation\n------------\n\n.. code-block:: shell\n\n    pip install aio-pika\n\n\nUsage example\n-------------\n\nSimple consumer:\n\n.. code-block:: python\n\n    import asyncio\n    import aio_pika\n    import aio_pika.abc\n\n\n    async def main(loop):\n        # Connecting with the given parameters is also possible.\n        # aio_pika.connect_robust(host=\"host\", login=\"login\", password=\"password\")\n        # You can only choose one option to create a connection, url or kw-based params.\n        connection = await aio_pika.connect_robust(\n            \"amqp://guest:guest@127.0.0.1/\", loop=loop\n        )\n\n        async with connection:\n            queue_name = \"test_queue\"\n\n            # Creating channel\n            channel: aio_pika.abc.AbstractChannel = await connection.channel()\n\n            # Declaring queue\n            queue: aio_pika.abc.AbstractQueue = await channel.declare_queue(\n                queue_name,\n                auto_delete=True\n            )\n\n            async with queue.iterator() as queue_iter:\n                # Cancel consuming after __aexit__\n                async for message in queue_iter:\n                    async with message.process():\n                        print(message.body)\n\n                        if queue.name in message.body.decode():\n                            break\n\n\n    if __name__ == \"__main__\":\n        loop = asyncio.get_event_loop()\n        loop.run_until_complete(main(loop))\n        loop.close()\n\nSimple publisher:\n\n.. code-block:: python\n\n    import asyncio\n    import aio_pika\n    import aio_pika.abc\n\n\n    async def main(loop):\n        # Explicit type annotation\n        connection: aio_pika.RobustConnection = await aio_pika.connect_robust(\n            \"amqp://guest:guest@127.0.0.1/\", loop=loop\n        )\n\n        routing_key = \"test_queue\"\n\n        channel: aio_pika.abc.AbstractChannel = await connection.channel()\n\n        await channel.default_exchange.publish(\n            aio_pika.Message(\n                body='Hello {}'.format(routing_key).encode()\n            ),\n            routing_key=routing_key\n        )\n\n        await connection.close()\n\n\n    if __name__ == \"__main__\":\n        loop = asyncio.get_event_loop()\n        loop.run_until_complete(main(loop))\n        loop.close()\n\n\nGet single message example:\n\n.. code-block:: python\n\n    import asyncio\n    from aio_pika import connect_robust, Message\n\n\n    async def main(loop):\n        connection = await connect_robust(\n            \"amqp://guest:guest@127.0.0.1/\",\n            loop=loop\n        )\n\n        queue_name = \"test_queue\"\n        routing_key = \"test_queue\"\n\n        # Creating channel\n        channel = await connection.channel()\n\n        # Declaring exchange\n        exchange = await channel.declare_exchange('direct', auto_delete=True)\n\n        # Declaring queue\n        queue = await channel.declare_queue(queue_name, auto_delete=True)\n\n        # Binding queue\n        await queue.bind(exchange, routing_key)\n\n        await exchange.publish(\n            Message(\n                bytes('Hello', 'utf-8'),\n                content_type='text/plain',\n                headers={'foo': 'bar'}\n            ),\n            routing_key\n        )\n\n        # Receiving message\n        incoming_message = await queue.get(timeout=5)\n\n        # Confirm message\n        await incoming_message.ack()\n\n        await queue.unbind(exchange, routing_key)\n        await queue.delete()\n        await connection.close()\n\n\n    if __name__ == \"__main__\":\n        loop = asyncio.get_event_loop()\n        loop.run_until_complete(main(loop))\n\n\nThere are more examples and the RabbitMQ tutorial in the `documentation`_.\n\nSee also\n==========\n\n`aiormq`_\n---------\n\n`aiormq` is a pure python AMQP client library. It is under the hood of **aio-pika** and might to be used when you really loving works with the protocol low level.\nFollowing examples demonstrates the user API.\n\nSimple consumer:\n\n.. code-block:: python\n\n    import asyncio\n    import aiormq\n\n    async def on_message(message):\n        \"\"\"\n        on_message doesn't necessarily have to be defined as async.\n        Here it is to show that it's possible.\n        \"\"\"\n        print(f\" [x] Received message {message!r}\")\n        print(f\"Message body is: {message.body!r}\")\n        print(\"Before sleep!\")\n        await asyncio.sleep(5)   # Represents async I/O operations\n        print(\"After sleep!\")\n\n    async def main():\n        # Perform connection\n        connection = await aiormq.connect(\"amqp://guest:guest@localhost/\")\n\n        # Creating a channel\n        channel = await connection.channel()\n\n        # Declaring queue\n        declare_ok = await channel.queue_declare('helo')\n        consume_ok = await channel.basic_consume(\n            declare_ok.queue, on_message, no_ack=True\n        )\n\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(main())\n    loop.run_forever()\n\nSimple publisher:\n\n.. code-block:: python\n\n    import asyncio\n    from typing import Optional\n\n    import aiormq\n    from aiormq.abc import DeliveredMessage\n\n    MESSAGE: Optional[DeliveredMessage] = None\n\n    async def main():\n        global MESSAGE\n        body = b'Hello World!'\n\n        # Perform connection\n        connection = await aiormq.connect(\"amqp://guest:guest@localhost//\")\n\n        # Creating a channel\n        channel = await connection.channel()\n        declare_ok = await channel.queue_declare(\"hello\", auto_delete=True)\n\n        # Sending the message\n        await channel.basic_publish(body, routing_key='hello')\n        print(f\" [x] Sent {body}\")\n\n        MESSAGE = await channel.basic_get(declare_ok.queue)\n        print(f\" [x] Received message from {declare_ok.queue!r}\")\n\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(main())\n\n    assert MESSAGE is not None\n    assert MESSAGE.routing_key == \"hello\"\n    assert MESSAGE.body == b'Hello World!'\n\nThe `patio`_ and the `patio-rabbitmq`_\n--------------------------------------\n\n**PATIO** is an acronym for Python Asynchronous Tasks for AsyncIO - an easily extensible library, for distributed task execution, like celery, only targeting asyncio as the main design approach.\n\n**patio-rabbitmq** provides you with the ability to use *RPC over RabbitMQ* services with extremely simple implementation:\n\n.. code-block:: python\n\n   from patio import Registry, ThreadPoolExecutor\n   from patio_rabbitmq import RabbitMQBroker\n\n   rpc = Registry(project=\"patio-rabbitmq\", auto_naming=False)\n\n   @rpc(\"sum\")\n   def sum(*args):\n       return sum(args)\n\n   async def main():\n       async with ThreadPoolExecutor(rpc, max_workers=16) as executor:\n           async with RabbitMQBroker(\n               executor, amqp_url=\"amqp://guest:guest@localhost/\",\n           ) as broker:\n               await broker.join()\n\nAnd the caller side might be written like this:\n\n.. code-block:: python\n\n    import asyncio\n    from patio import NullExecutor, Registry\n    from patio_rabbitmq import RabbitMQBroker\n\n    async def main():\n        async with NullExecutor(Registry(project=\"patio-rabbitmq\")) as executor:\n            async with RabbitMQBroker(\n                executor, amqp_url=\"amqp://guest:guest@localhost/\",\n            ) as broker:\n                print(await asyncio.gather(\n                    *[\n                        broker.call(\"mul\", i, i, timeout=1) for i in range(10)\n                     ]\n                ))\n\n\n`FastStream`_\n---------------\n\n**FastStream** is a powerful and easy-to-use Python library for building asynchronous services that interact with event streams..\n\nIf you need no deep dive into **RabbitMQ** details, you can use more high-level **FastStream** interfaces:\n\n.. code-block:: python\n\n   from faststream import FastStream\n   from faststream.rabbit import RabbitBroker\n\n   broker = RabbitBroker(\"amqp://guest:guest@localhost:5672/\")\n   app = FastStream(broker)\n\n   @broker.subscriber(\"user\")\n   async def user_created(user_id: int):\n       assert isinstance(user_id, int)\n       return f\"user-{user_id}: created\"\n\n   @app.after_startup\n   async def pub_smth():\n       assert (\n           await broker.publish(1, \"user\", rpc=True)\n       ) ==  \"user-1: created\"\n\nAlso, **FastStream** validates messages by **pydantic**, generates your project **AsyncAPI** spec, supports In-Memory testing, RPC calls, and more.\n\nIn fact, it is a high-level wrapper on top of **aio-pika**, so you can use both of these libraries' advantages at the same time.\n\n`python-socketio`_\n------------------\n\n`Socket.IO`_ is a transport protocol that enables real-time bidirectional event-based communication between clients (typically, though not always, web browsers) and a server. This package provides Python implementations of both, each with standard and asyncio variants.\n\nAlso this package is suitable for building messaging services over **RabbitMQ** via **aio-pika** adapter:\n\n.. code-block:: python\n\n   import socketio\n   from aiohttp import web\n\n   sio = socketio.AsyncServer(client_manager=socketio.AsyncAioPikaManager())\n   app = web.Application()\n   sio.attach(app)\n\n   @sio.event\n   async def chat_message(sid, data):\n       print(\"message \", data)\n\n   if __name__ == '__main__':\n       web.run_app(app)\n\nAnd a client is able to call `chat_message` the following way:\n\n.. code-block:: python\n\n   import asyncio\n   import socketio\n\n   sio = socketio.AsyncClient()\n\n   async def main():\n       await sio.connect('http://localhost:8080')\n       await sio.emit('chat_message', {'response': 'my response'})\n\n   if __name__ == '__main__':\n       asyncio.run(main())\n\nThe `taskiq`_ and the `taskiq-aio-pika`_\n----------------------------------------\n\n**Taskiq** is an asynchronous distributed task queue for python. The project takes inspiration from big projects such as Celery and Dramatiq. But taskiq can send and run both the sync and async functions.\n\nThe library provides you with **aio-pika** broker for running tasks too.\n\n.. code-block:: python\n\n   from taskiq_aio_pika import AioPikaBroker\n\n   broker = AioPikaBroker()\n\n   @broker.task\n   async def test() -\u003e None:\n       print(\"nothing\")\n\n   async def main():\n       await broker.startup()\n       await test.kiq()\n\n`Rasa`_\n-------\n\nWith over 25 million downloads, Rasa Open Source is the most popular open source framework for building chat and voice-based AI assistants.\n\nWith **Rasa**, you can build contextual assistants on:\n\n* Facebook Messenger\n* Slack\n* Google Hangouts\n* Webex Teams\n* Microsoft Bot Framework\n* Rocket.Chat\n* Mattermost\n* Telegram\n* Twilio\n\nYour own custom conversational channels or voice assistants as:\n\n* Alexa Skills\n* Google Home Actions\n\n**Rasa** helps you build contextual assistants capable of having layered conversations with lots of back-and-forth. In order for a human to have a meaningful exchange with a contextual assistant, the assistant needs to be able to use context to build on things that were previously discussed – **Rasa** enables you to build assistants that can do this in a scalable way.\n\nAnd it also uses **aio-pika** to interact with **RabbitMQ** deep inside!\n\nVersioning\n==========\n\nThis software follows `Semantic Versioning`_\n\n\nFor contributors\n----------------\n\nSetting up development environment\n__________________________________\n\nClone the project:\n\n.. code-block:: shell\n\n    git clone https://github.com/mosquito/aio-pika.git\n    cd aio-pika\n\nCreate a new virtualenv for `aio-pika`_:\n\n.. code-block:: shell\n\n    python3 -m venv env\n    source env/bin/activate\n\nInstall all requirements for `aio-pika`_:\n\n.. code-block:: shell\n\n    pip install -e '.[develop]'\n\n\nRunning Tests\n_____________\n\n**NOTE: In order to run the tests locally you need to run a RabbitMQ instance with default user/password (guest/guest) and port (5672).**\n\nThe Makefile provides a command to run an appropriate RabbitMQ Docker image:\n\n.. code-block:: bash\n\n    make rabbitmq\n\nTo test just run:\n\n.. code-block:: bash\n\n    make test\n\n\nEditing Documentation\n_____________________\n\nTo iterate quickly on the documentation live in your browser, try:\n\n.. code-block:: bash\n\n    nox -s docs -- serve\n\nCreating Pull Requests\n______________________\n\nPlease feel free to create pull requests, but you should describe your use cases and add some examples.\n\nChanges should follow a few simple rules:\n\n* When your changes break the public API, you must increase the major version.\n* When your changes are safe for public API (e.g. added an argument with default value)\n* You have to add test cases (see `tests/` folder)\n* You must add docstrings\n* Feel free to add yourself to `\"thank's to\" section`_\n\n\n.. _\"thank's to\" section: https://github.com/mosquito/aio-pika/blob/master/docs/source/index.rst#thanks-for-contributing\n.. _Semantic Versioning: http://semver.org/\n.. _aio-pika: https://github.com/mosquito/aio-pika/\n.. _faststream: https://github.com/airtai/faststream\n.. _patio: https://github.com/patio-python/patio\n.. _patio-rabbitmq: https://github.com/patio-python/patio-rabbitmq\n.. _Socket.IO: https://socket.io/\n.. _python-socketio: https://python-socketio.readthedocs.io/en/latest/intro.html\n.. _taskiq: https://github.com/taskiq-python/taskiq\n.. _taskiq-aio-pika: https://github.com/taskiq-python/taskiq-aio-pika\n.. _Rasa: https://rasa.com/docs/rasa/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmosquito%2Faio-pika","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmosquito%2Faio-pika","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmosquito%2Faio-pika/lists"}