Install & Compatibility
Where this runs
tested against v6.9.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.360s · 20.7MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.7s · import 0.342s · 21MB
19MB installed
● package 19MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
connect
✓ from aiormq import connect
Channel
✓ from aiormq.abc import Channel
While Channel is part of the internal structure, for type hinting, import from `aiormq.abc`.
IncomingMessage
✓ from aiormq.abc import IncomingMessage
Required for type hinting message callbacks during consumption.
This quickstart demonstrates how to connect to an AMQP broker (like RabbitMQ), declare a queue, publish a message, and consume messages asynchronously. It uses `os.environ.get` for the AMQP URL, making it easy to configure without hardcoding credentials. Remember to have a RabbitMQ instance running at `localhost:5672` or specify a different `AMQP_URL`.
import asyncio
import os
from aiormq import connect
from aiormq.abc import IncomingMessage
# Get AMQP URL from environment variable, default to local RabbitMQ
AMQP_URL = os.environ.get('AMQP_URL', 'amqp://guest:guest@localhost/')
QUEUE_NAME = 'aiormq_test_queue'
async def on_message(message: IncomingMessage):
"""Callback for consuming messages."""
print(f"[x] Received: {message.body.decode()}")
await message.ack() # Acknowledge the message
async def main():
connection = None
try:
# Establish connection
print(f"[*] Connecting to {AMQP_URL}...")
connection = await connect(AMQP_URL)
print("[*] Connection established.")
# Create a channel
channel = await connection.channel()
print("[*] Channel created.")
# Declare a queue (idempotent operation)
await channel.queue_declare(QUEUE_NAME)
print(f"[*] Queue '{QUEUE_NAME}' declared.")
# Publish a message
message_body = b"Hello, aiormq world!"
await channel.basic_publish(
exchange='',
routing_key=QUEUE_NAME,
body=message_body
)
print(f"[x] Published message: '{message_body.decode()}'")
# Start consuming messages
consumer_tag = await channel.basic_consume(QUEUE_NAME, on_message)
print(f"[*] Consuming from '{QUEUE_NAME}'. Consumer tag: {consumer_tag}")
# Keep the consumer running for a short period (e.g., 5 seconds)
print("[*] Waiting for messages... Press Ctrl+C to exit")
await asyncio.sleep(5)
# Stop consuming
await channel.basic_cancel(consumer_tag)
print(f"[*] Consumer '{consumer_tag}' cancelled.")
except Exception as e:
print(f"[!] An error occurred: {e}")
finally:
if connection:
print("[*] Closing connection...")
await connection.close()
print("[*] Connection closed.")
if __name__ == '__main__':
asyncio.run(main())
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'aiormq'
The 'aiormq' package is not installed in the Python environment.
fixInstall the package using pip: 'pip install aiormq'.
ImportError: cannot import name 'connect' from 'aiormq'
The 'connect' function does not exist in the 'aiormq' module.
fixUse 'from aiormq import Connection' and then 'connection = await Connection.connect()'.
AttributeError: module 'aiormq' has no attribute 'Channel'
The 'Channel' class is not directly accessible from the 'aiormq' module.
fixAccess the 'Channel' class through an established connection: 'channel = await connection.channel()'.
TypeError: 'NoneType' object is not callable
Attempting to call a method on a 'None' object, possibly due to a failed connection.
fixEnsure the connection is successfully established before calling methods: 'connection = await aiormq.connect()'.
RuntimeError: Event loop is closed
The asyncio event loop has been closed before the asynchronous operation could complete.
fixEnsure the event loop is running when performing asynchronous operations: 'asyncio.run(main())'.
Upgrade
Version history
7.0.0latest on PyPI · released Jul 9, 2026
Audit
Dependencies
pamqprequiredCore dependency for AMQP 0.9.1 protocol framing.