Messaging

Libraries for working with message brokers and event streaming.

Instead of a Python messaging library per broker, an asyncio service can run on FastStream. Otherwise, use confluent-kafka, pika, or paho-mqtt.

How to choose:

  • An asyncio service on Kafka, RabbitMQ, MQTT, NATS, or Redis: FastStream
  • Kafka, including Confluent's Schema Registry: confluent-kafka
  • RabbitMQ, with the client its team recommends: pika
  • IoT devices and sensors that speak MQTT: paho-mqtt

Listed in editorial order. Click a column header to re-sort the whole list.

Press / to search. Tags open their category. Click a row for details.

Search and filter

Results

Row number Tags
Confluent's Python client for Apache Kafka, built on librdkafka.
Pure-Python RabbitMQ/AMQP 0-9-1 client library.
pika/github.com/pika/pika /3,890 stars /
The Eclipse Paho MQTT client for Python.
A framework for building async services over Kafka, RabbitMQ, NATS, MQTT, and Redis.
ag2ai/github.com/ag2ai/faststream /5,387 stars /

Messaging guide

confluent-kafka is Confluent's Kafka client, a binding on top of librdkafka, the C client. produce() only queues a message, so call poll() to get delivery reports. Its README says production apps should serialize with Schema Registry instead of producing raw bytes.

pika is a pure-Python implementation of AMQP 0-9-1, and RabbitMQ's tutorials use it as the Python client the RabbitMQ team recommends. Start with BlockingConnection, as those tutorials do: it's the adapter for a procedural style. Ack each message after processing it, so RabbitMQ redelivers it when a worker dies.

paho-mqtt is the Eclipse Foundation's MQTT client, and MQTT is a lightweight publish/subscribe protocol for IoT devices and low-bandwidth links. Create a client, connect it, and run one of its network loops. loop_forever() blocks until you disconnect, and loop_start() runs the loop in a background thread. Both reconnect for you. Subscribe in on_connect(), so a reconnect renews your subscriptions.

FastStream is an asynchronous framework for event-driven services: FastAPI's decorators, type-driven validation, and dependency injection, pointed at Kafka, RabbitMQ, NATS, Redis, or MQTT instead of HTTP. Write handlers with @broker.subscriber() and @broker.publisher(), run the app with faststream run, and test it in memory with no broker running. It wraps your broker's own client and leaves out retries, delayed delivery, and task orchestration by design: for background jobs, see Task Queues.

In asyncio code, pick a client that won't block the event loop. FastStream is asynchronous throughout, confluent-kafka has AsyncIO clients for apps like a FastAPI service, and pika has an asyncio connection adapter.

Know a project that belongs here?

Tell us what it does and why it stands out.