aio-pika is an asyncio-native Python library providing a high-level wrapper around `aiormq` for interacting with AMQP brokers like RabbitMQ. It simplifies common messaging patterns, offering both basic and robust (auto-reconnecting) connections. The library is actively maintained with frequent patch and minor releases, ensuring compatibility and bug fixes.
pip install aio-pikaVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to establish a robust connection, declare a queue, publish a message, and consume it using aio-pika. It highlights the use of `connect_robust` for production readiness and explicit message acknowledgment. Make sure a RabbitMQ instance is running on `localhost`.
Upgrade your Python environment to 3.8+ or pin `aio-pika<9.4.0` in your dependencies.
Use `aio_pika.Channel.get_underlay_channel()` instead if you need to access the raw `aiormq` channel object. It's generally recommended to stick to `aio-pika`'s higher-level API.
`connect_robust()` automatically handles connection and channel re-establishment upon network disconnections, making your application more resilient to transient failures. `connect()` does not provide this robustness.
Upgrade to `aio-pika` version 9.4.2 or higher to ensure proper message `nack` behavior during consumer cancellation.
Always use `async with message.process():` for automatic acknowledgment/rejection on task completion/failure, or call `message.ack()`/`message.nack()` manually to prevent messages from remaining in the queue indefinitely or being redelivered unnecessarily.
Install the module using pip: 'pip install aio-pika'.
Ensure you have the latest version of 'aio-pika' installed: 'pip install --upgrade aio-pika'.
Verify that the RabbitMQ server is running and accessible at the specified host and port.
Ensure that the event loop remains open until all tasks are finished, and avoid closing it prematurely.
Use a valid AMQP URL scheme, such as 'amqp://user:password@host:port/'.