API Reference
Pika
Pure-Python AMQP 0-9-1 client for RabbitMQ with blocking connections and channel methods.
Official Documentation ↗CompatibilityThis documentation covers version
v1.3. Check the official docs for the latest API surface.Installation
pip
pip install pikaMethods
No methods match this filter.
Pika speaks AMQP to RabbitMQ, with BlockingConnection for simple code and adapters for asyncio.
Key Features
- BlockingConnection for straightforward scripts
- Publisher confirms and consumer callbacks
- Multiple adapters including asyncio
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The official API reference declares the following error types:
pika.exceptions.AMQPConnectionError(exception) — official text: “exception pika.exceptions.AMQPConnectionError” (source: https://pika.readthedocs.io/en/stable/modules/exceptions.html#pika.exceptions.AMQPConnectionError, fetched 2026-11-08T16:03:08.4363995+08:00)pika.exceptions.ConnectionClosed(exception) — official text: “class ConnectionClosed(AMQPConnectionError): def init(self, reply_code, reply_text):” (source: https://raw.githubusercontent.com/pika/pika/1.3.2/pika/exceptions.py, fetched 2026-11-08T16:03:08.4363995+08:00)pika.exceptions.ChannelClosed(exception) — official text: “class ChannelClosed(AMQPChannelError): “”“The channel closed by client or by broker”“”” (source: https://raw.githubusercontent.com/pika/pika/1.3.2/pika/exceptions.py, fetched 2026-11-08T16:03:08.4363995+08:00)
API reference evidence
Fetched from official sources on 2026-11-08T16:03:08.4363995+08:00 via WebFetch 官方 API 页面;BlockingConnection 因官方文档已将其移除,改用官方仓库 1.3.2 源码 docstring(raw.githubusercontent.com/pika/pika/1.3.2/…).
pika.BlockingConnection→ signature from https://raw.githubusercontent.com/pika/pika/1.3.2/pika/adapters/blocking_connection.py; official text: “class BlockingConnection(AbstractConnection): def init(self, parameters=None, _impl_class=None): “”“Create a new instance of the connection object.”“””channel.basic_publish→ signature from https://pika.readthedocs.io/en/stable/modules/channel.html#pika.channel.Channel.basic_publish; official text: “basic_publish(exchange: str, routing_key: str, body: bytes, properties: BasicProperties | None = None, mandatory: bool = False) -> None”channel.basic_consume→ signature from https://pika.readthedocs.io/en/stable/modules/channel.html#pika.channel.Channel.basic_consume; official text: “basic_consume(queue: str, on_message_callback: _OnMessageCallback, auto_ack: bool = False, exclusive: bool = False, consumer_tag: str | None = None, arguments: dict[str, Any] | None = None, callback: _OnBasicConsumeCallb”
FAQ
- Why is BlockingConnection not thread safe?
- It multiplexes frames on one socket, so concurrent use corrupts state. Create one connection per thread or use a pooling library.
- How do I ensure delivery?
- Enable publisher confirms and declare durable queues; ack messages only after successful processing.
- What happens on connection loss?
- Pika raises an exception. Implement reconnect logic or use a library such as aio-pika that offers robust reconnection.
Report a problem with this API docOpens a pre-filled issue on GitHub.