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

pippip install pika

Methods

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:

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/…).

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.