Library / SDK
pika/pika avatar
pika/pika

Pika has no dependencies and seven adapters, and threading is its sharp edge

Pure Python RabbitMQ/AMQP 0-9-1 client library

3,895 stars861 forksPythonBSD-3-Clause

At a glance

What is it?
Pika is a pure Python implementation of the AMQP 0-9-1 protocol including RabbitMQ's own extensions, with an empty dependency list and seven connection adapters covering blocking, asynchronous, cooperative and thread-safe styles. Its documentation is unusually candid about the one place applications break: a slow consumer on a single threaded adapter can lose the connection to a heartbeat timeout.
Who is it for?
Pika suits an application that must speak to RabbitMQ without pulling in a C extension or a framework, and that has to choose between a blocking call style and an event loop. It does not suit a consumer that does slow work per message on a single threaded adapter, since the connection can drop on a heartbeat timeout.
Can I use it commercially?
Yes. BSD-3-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • pika/pika3,895 ★ · +8
Star history
Repository2026-09-242026-11-15
pika/pika3.9k3.9k

8 Stars in the last 52 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The dependency list is empty, and that is the design

The manifest declares the package as a pure Python client with no runtime dependencies at all, and the extras exist only for the three optional adapters. That is the whole argument for the library: if you need cooperative concurrency, you install the adapter's own library, and if you do not, you install nothing. The metadata calls the project a production stable library and classifies it for operating system independence, with implementations listed for the two main interpreters and one alternative. The protocol it implements is version 0-9-1, and the description adds a clause that matters for anyone targeting a broker: RabbitMQ's own extensions are included, so the feature set is broader than the base specification. The oldest supported interpreter is still in the classifier list, and the file notes which release was the last one to support Python 2.7.

Seven adapters, and the choice is really your event loop

The adapter list is the API surface, and it is ordered by the loop you already run. There is a blocking connection, described as synchronous and aimed at simple usage, which is what the shortest example uses:

python
import pika

connection = pika.BlockingConnection()
channel = connection.channel()
channel.basic_publish(exchange='test', routing_key='test',
                      body=b'Test message.')
connection.close()

There is a select based connection, described as asynchronous with no third party dependencies, which is the fallback when you have no event loop at all. Then one adapter per framework: one for the standard library's asynchronous loop, and one each for a cooperative concurrency library, a web framework's loop, and a reactor style networking library. The seventh is the odd one out, a thread-safe adapter that runs the select connection's loop in a background thread and makes every channel method safe to call from any thread at once. So the question is not which adapter is best but which loop your process already owns.

Most adapters are single threaded, and the file explains the choice

The introduction makes a point about threads that is easy to miss. The library does not require them, and the core deliberately takes care not to forbid them either, and the same courtesy extends to greenlets, callbacks, continuations and generators. Then the practical sentence: most connection adapters are single threaded, and you should use the thread-safe connection when you need to publish or consume from several threads. The stated reason for the general position is compatibility, because applications get network events in many different ways, from direct sockets to a plain select call, and the library tries to stay usable in all of them and to be easy to adapt to a new environment. The cost of that breadth is that the default object is not thread safe, and the documentation puts the burden of noticing that on the reader.

The failure mode is a heartbeat timeout in a slow consumer

The threading section explains what actually goes wrong, and it is more useful than a warning about thread safety. With a single threaded connection confined to one thread, a consumer that takes a long time to process a message may see the connection dropped, and the reason given is the AMQP heartbeat timeout: the loop is blocked doing your work and cannot service the heartbeat. The recommended fix is the thread-safe adapter, which runs the loop in a background thread and gives you a blocking API that any number of threads can call at once, and the detail that matters most is that consumer callbacks run on a per-channel worker thread, so slow processing need not stall heartbeats as long as the callback keeps pace with deliveries. The manual alternative is to schedule a callback into the loop thread, and the example for that comes with a protocol constraint written into its docstring: the channel used to acknowledge must be the same channel instance the message was delivered on.

Fault tolerance is a tuple of connection parameters

Failover in this library is not a retry loop, it is a data structure. You pass several connection parameter objects to the connection instead of one, each naming a different host, and the last element in the sequence is where you enable retries by setting the attempt count and the delay between them. The stated semantics are precise: retries occur after connection attempts using all of the given parameters have failed, which means the list is tried in order first and only then does the retry policy apply. The blocking adapter accepts the tuple directly. The non-blocking adapters do not take it in the constructor, so the same tuple is passed through the adapter's connection creation class method instead, which is the one API difference between the two styles that a porting attempt will hit first.

The examples directory is a catalogue of protocol features

The example files are named well enough to double as a feature index, and reading the list tells you which rabbit holes the maintainers expect. There are separate examples for delivery confirmations, for publishing as mandatory, for the direct reply to extension, and for heartbeat and blocked timeouts, which are the three places a publisher or consumer surprises people. There is a pair comparing synchronous and asynchronous publishing, which suggests the adapter choice is the thing people are unsure about. TLS consumption has its own file, as does recovery across multiple hosts, in two variants that presumably differ in whether retries are configured. Then the shapes: a generator based consumer, a basic get, a queued consumer, a long running publisher, a confirmation flow, and a small set of threaded consumer and publisher files that match the recommended adapter.

The manifest says 1.4.0 and the releases are already at 1.4.4

Two version facts in the same repository do not line up, and it is the kind of thing worth knowing before you pin. The declared version in the build manifest is 1.4.0, while the recent published releases are 1.4.1, 1.4.2 and 1.4.4, the last of them from August 2026. So the number in the manifest lags the published history, which usually means the release tooling writes the version at tag time rather than a maintainer editing the file. The interpreter story has the same flavour: the classifiers run from 3.7 to 3.14 and the requirement is 3.7 or newer, while the linting configuration still targets the oldest of those, which tells you the tooling has not been moved forward even though the metadata advertises new interpreters. The last push to the default branch is dated 2026-10-01 and the repository is not archived.

Three changelog files and a docs build sit at the root

The repository root explains how the project is organised to contribute to it rather than to use it. There is a current changelog, a historical changelog, and a history file, so the release record is split rather than linear, which is what a project that has been around for a decade of Python versions tends to do. There is a release document, a contributing guide, a licence under a three clause BSD, and a package manifest file for the source distribution. The documentation is built with a static site generator from the docs directory, with a configuration file for it at the root, and the same site is what the homepage points at. Two configuration files sit alongside the linting settings: one for the type checker and one section for a different checker, plus an overrides directory, which together suggest type checking is a first class part of the build rather than an afterthought.

Editorial conclusion

Pika suits an application that must speak to RabbitMQ without pulling in a C extension or a framework, and that has to choose between a blocking call style and an event loop. It does not suit a consumer that does slow work per message on a single threaded adapter, since the connection can drop on a heartbeat timeout. Before writing consumer code, decide whether you need the thread-safe adapter, and if you use the manual approach, remember the protocol constraint that an acknowledgement has to go through the same channel object the message arrived on.

Frequently asked questions

What is Pika and what does it implement?

A pure Python implementation of the AMQP 0-9-1 protocol, including RabbitMQ's own extensions, for talking to a RabbitMQ broker. The project ships no runtime dependencies at all, with extras only for the cooperative and framework specific adapters.

Which Pika adapter should I use?

It depends on the loop your process already runs. There is a blocking connection for simple synchronous use, a select based connection with no third party dependencies, one adapter for the standard library's asynchronous loop and one each for a cooperative concurrency library, a web framework loop, a reactor style library, and a thread-safe adapter that runs the select connection's loop in a background thread.

Why does my Pika consumer keep dropping its connection?

A single threaded adapter whose consumer takes a long time to process a message can miss the AMQP heartbeat timeout, because the loop is blocked doing your work. The fix is the thread-safe adapter, whose consumer callbacks run on a per-channel worker thread so slow processing never stalls heartbeats, or scheduling the acknowledgement into the loop thread manually.

How do I make Pika fail over between brokers?

Pass several connection parameter objects, one per host, and set the attempt count and retry delay on the last element of the sequence. Retries only happen after attempts using all the given parameters have failed, and non-blocking adapters take the same tuple through their connection creation class method rather than the constructor.

What is the latest Pika version?

The recent releases are 1.4.1, 1.4.2 and 1.4.4, the last published in August 2026, while the build manifest still declares 1.4.0. The licence is a three clause BSD and the library is classified as production stable.

Official sources

  1. License: BSD-3-Clause
  2. pika/pika on GitHub
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/pika-pika.svg)](https://hysenlabs.com/projects/pika-pika)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/pika-pika.svg)](https://hysenlabs.com/projects/pika-pika)

Was this useful?