# Python kafka libraries

Python Kafka libraries connect applications to Apache Kafka to publish messages to topics and consume them from partitions. A client either implements the Kafka protocol in Python or wraps librdkafka, the C client library. These libraries let backend services and data pipelines stream events between systems.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [confluent-kafka](#confluent-kafka) | 46.4M | 528 | Nov 2026 | Apache-2.0 |
| [kafka-python](#kafka-python) | 18.5M | 5.9K | Nov 2026 | Apache-2.0 |
| [aiokafka](#aiokafka) | 15.0M | 1.4K | Oct 2026 | Apache-2.0 |
| [FastStream](#faststream) | 1.9M | 5.4K | Oct 2026 | Apache-2.0 |
| [faust-streaming](#faust-streaming) | 288.1K | 1.9K | Oct 2026 | BSD-3-Clause |
| [Quix Streams](#quix-streams) | 86.3K | 1.6K | Oct 2026 | Apache-2.0 |
| [Arroyo](#sentry-arroyo) | 26.4K | 63 | Nov 2026 | Apache-2.0 |
| [PyKafka](#pykafka) | 16.8K | 1.1K | Sep 2018 | Apache-2.0 |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[confluent-kafka](#confluent-kafka) has the most monthly downloads in this comparison, at 46.4M.

## Capabilities

| Library | Native asyncio API | librdkafka backend |
| --- | --- | --- |
| [confluent-kafka](#confluent-kafka) | Yes | Yes |
| [kafka-python](#kafka-python) | No | No |
| [aiokafka](#aiokafka) | Yes | No |
| [FastStream](#faststream) | Yes | Via plugin |
| [faust-streaming](#faust-streaming) | Yes | Via plugin |
| [Quix Streams](#quix-streams) | No | Yes |
| [Arroyo](#sentry-arroyo) | No | Yes |
| [PyKafka](#pykafka) | No | Via plugin |

## Libraries

### confluent-kafka

[GitHub](https://github.com/confluentinc/confluent-kafka-python) · [PyPI](https://pypi.org/project/confluent-kafka) · [Docs](https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html)

Provides Kafka producer, consumer, and administration APIs backed by librdkafka.

- Downloads / mo: 46.4M
- Stars: 528
- Last release: 2.16.2
- License: Apache-2.0
- Capabilities: [From the confluent-kafka docs](https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html)

**Strengths**

- **Provides an asyncio producer.** Use the asynchronous producer inside applications with an asyncio event loop.
- **Supports transactional Kafka workflows.** Use the client transaction APIs for atomic Kafka processing.

**Watch out for**

- **Async batching omits message headers.** Use synchronous produce when each message needs headers.
- **Delivery callbacks need polling.** Poll the synchronous producer to run queued delivery callbacks.

```sh
pip install confluent-kafka
```

**RasaHQ/rasa** (21.4K stars)

[RasaHQ/rasa](https://github.com/RasaHQ/rasa) 

```python
def _publish(self, event: Dict[Text, Any]) -> None:
    if self.partition_by_sender:
        partition_key = bytes(event.get("sender_id"), encoding=DEFAULT_ENCODING)
    else:
        partition_key = None

    headers = []
    if self.rasa_environment:
        headers = [
            (
                "RASA_ENVIRONMENT",
                bytes(self.rasa_environment, encoding=DEFAULT_ENCODING),
            )
        ]

    reduced_event = rasa.shared.core.events.remove_parse_data(event)
    structlogger.debug(
        "kafka.publish.event",
        event_info="Logging a reduced version of the Kafka event",
        topic=self.topic,
        rasa_event=reduced_event,
        partition_key=partition_key,
        headers=headers,
    )

    serialized_event = json.dumps(event).encode(DEFAULT_ENCODING)

    if self.producer is not None:
        self.producer.produce(
            self.topic,
            value=serialized_event,
            key=partition_key,
            headers=headers,
            on_delivery=delivery_report,
        )

```

[rasa/core/brokers/kafka.py](https://github.com/RasaHQ/rasa/blob/c4069568b4fe2adb5d5a1e55d17ce8cb9dda27fc/rasa/core/brokers/kafka.py#L231-L265) · [More projects using confluent-kafka →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20confluent-kafka%20for%20Kafka%20offset%20commits%2C%20partition%20reassignment%2C%20batch%20publishing%20and%20event-delivery%20callbacks&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import asyncio
from confluent_kafka.aio import AIOProducer

async def main():
    p = AIOProducer({"bootstrap.servers": "mybroker"})
    try:
        # produce() returns a Future; first await the coroutine to get the Future,
        # then await the Future to get the delivered Message.
        delivery_future = await p.produce("mytopic", value=b"hello")
        delivered_msg = await delivery_future
        # Optionally flush any remaining buffered messages before shutdown
        await p.flush()
    finally:
        await p.close()

asyncio.run(main())

```

From [README.md](https://github.com/confluentinc/confluent-kafka-python/blob/master/README.md)

### kafka-python

[GitHub](https://github.com/dpkp/kafka-python) · [PyPI](https://pypi.org/project/kafka-python) · [Docs](https://kafka-python.readthedocs.io/en/master/)

Provides pure-Python Kafka producer, consumer, and administration clients.

- Downloads / mo: 18.5M
- Stars: 5.9K
- Last release: 3.0.13
- License: Apache-2.0
- Capabilities: [From the kafka-python docs](https://kafka-python.readthedocs.io/en/master/)

**Strengths**

- **Installs without a native core.** Use producer, consumer, and admin clients without a compiled client dependency.
- **Supports transactional message publishing.** Commit or abort the messages sent within a producer transaction.

**Watch out for**

- **Consumers belong to one thread.** Keep each consumer instance within its own thread.
- **Waiting for delivery blocks.** Keep blocking future waits outside an application event loop.

```sh
pip install kafka-python
```

**YelpArchive/kafka-utils** (316 stars)

[YelpArchive/kafka-utils](https://github.com/YelpArchive/kafka-utils) 

```python
def remove_partition_from_consumer(self, partition):
    deleted = self.active_partitions.pop(partition)
    # Terminate if there are no more partitions to consume
    if not self.active_partitions:
        self.log.info("Completed reading from all partitions")
        self._finished = True
        return
    # Reassign the remaining partitions to the consumer while saving the
    # position
    positions = [
        (p, self.consumer.position(p))
        for p in self.active_partitions.values()
    ]
    self.consumer.assign(list(self.active_partitions.values()))
    for topic_partition, position in positions:
        self.consumer.seek(topic_partition, position)
    self.log.info(
        "Completed reading from %s. Remaining partitions: %s",
        deleted,
        self.active_partitions,
    )

```

[kafka_utils/kafka_consumer_manager/util.py](https://github.com/YelpArchive/kafka-utils/blob/def433ec4d07c60290d5dc937d3b4e5189eca9dc/kafka_utils/kafka_consumer_manager/util.py#L374-L394) · [More projects using kafka-python →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20kafka-python%20for%20Kafka%20offset%20commits%2C%20partition%20reassignment%2C%20batch%20publishing%20and%20event-delivery%20callbacks&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
# Serialize json messages
from kafka import KafkaProducer, JsonSerializer
producer = KafkaProducer(value_serializer=JsonSerializer())
producer.send('fizzbuzz', {'foo': 'bar'})

```

From [example.py](https://github.com/dpkp/kafka-python/blob/master/README.rst)

### aiokafka

[GitHub](https://github.com/aio-libs/aiokafka) · [PyPI](https://pypi.org/project/aiokafka) · [Docs](https://aiokafka.readthedocs.io/en/stable/)

Provides asyncio producer and consumer APIs for Apache Kafka.

- Downloads / mo: 15.0M
- Stars: 1.4K
- Last release: 0.15.0
- License: Apache-2.0
- Capabilities: [From the aiokafka docs](https://aiokafka.readthedocs.io/en/stable/)

**Strengths**

- **Fits async producer lifecycles.** Await producer startup, delivery, and shutdown from the application event loop.
- **Coordinates consumer groups.** Distribute topic partitions among consumers in the same group.

**Watch out for**

- **Producer memory limit needs handling.** Manage total buffered data outside the missing buffer.memory setting.
- **Send timeouts need explicit wrapping.** Wrap producer.send with asyncio.wait_for when a bounded wait is required.

```sh
pip install aiokafka
```

**ag2ai/faststream** (5.4K stars)

[ag2ai/faststream](https://github.com/ag2ai/faststream) 

```python
@override
async def publish_batch(
    self,
    cmd: "KafkaPublishCommand",
) -> Union["asyncio.Future[RecordMetadata]", "RecordMetadata"]:
    """Publish a batch of messages to a topic."""
    batch = self._producer.producer.create_batch()

    headers_to_send = cmd.headers_to_publish()

    if isinstance(self.codec, BatchCodecProto):
        encoded_batch = await self.codec.encode_batch(
            cmd.batch_bodies, self.serializer
        )
    else:
        encoded_batch = [
            await self.codec.encode(body, self.serializer)
            for body in cmd.batch_bodies
        ]

    for message_position, (message, content_type) in enumerate(encoded_batch):
        if content_type:
            final_headers = {
                "content-type": content_type,
                **headers_to_send,
            }
        else:
            final_headers = headers_to_send.copy()

        metadata = batch.append(
            key=cmd.key_for(message_position),
            value=message,
            timestamp=cmd.timestamp_ms,
            headers=encode_headers(final_headers),
        )
        if metadata is None:
            raise BatchBufferOverflowException(message_position=message_position)

    send_future = await self._producer.producer.send_batch(
        batch,
        cmd.destination,
        partition=cmd.partition,
    )
    if not cmd.no_confirm:
        return await send_future
    return send_future

```

[faststream/kafka/publisher/producer.py](https://github.com/ag2ai/faststream/blob/aa3d3c82410de58b8f32c5f39b0f42a98fd2d0a5/faststream/kafka/publisher/producer.py#L150-L195) · [More projects using aiokafka →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20aiokafka%20for%20Kafka%20offset%20commits%2C%20partition%20reassignment%2C%20batch%20publishing%20and%20event-delivery%20callbacks&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from aiokafka import AIOKafkaProducer
import asyncio

async def send_one():
    producer = AIOKafkaProducer(bootstrap_servers='localhost:9092')
    # Get cluster layout and initial topic/partition leadership information
    await producer.start()
    try:
        # Produce message
        await producer.send_and_wait("my_topic", b"Super message")
    finally:
        # Wait for all pending messages to be delivered or expire.
        await producer.stop()

asyncio.run(send_one())

```

From [README.rst](https://github.com/aio-libs/aiokafka/blob/master/README.rst)

### FastStream

[GitHub](https://github.com/ag2ai/faststream) · [PyPI](https://pypi.org/project/faststream) · [Docs](https://faststream.ag2.ai/latest/)

Connects to Kafka, RabbitMQ, NATS, Redis, and MQTT through one typed client.

- Downloads / mo: 1.9M
- Stars: 5.4K
- Last release: 0.7.8
- License: Apache-2.0
- Capabilities: [From the FastStream docs](https://faststream.ag2.ai/latest/)

```sh
pip install 'faststream[kafka,cli]'
```

**Quickstart**

```python
from faststream import FastStream
from faststream.kafka import KafkaBroker
# from faststream.confluent import KafkaBroker
# from faststream.rabbit import RabbitBroker
# from faststream.nats import NatsBroker
# from faststream.redis import RedisBroker
# from faststream.mqtt import MQTTBroker

broker = KafkaBroker("localhost:9092")
# broker = RabbitBroker("amqp://guest:guest@localhost:5672/")
# broker = NatsBroker("nats://localhost:4222/")
# broker = RedisBroker("redis://localhost:6379/")
# broker = MQTTBroker("localhost")

app = FastStream(broker)

@broker.subscriber("in")
@broker.publisher("out")
async def handle_msg(user: str, user_id: int) -> str:
    return f"User: {user_id} - {user} registered"

```

From [README.md](https://github.com/ag2ai/faststream/blob/main/README.md) · [Find projects using FastStream →](https://dashboard.exa.ai/playground/search?q=faststream%20GitHub%20projects)

### faust-streaming

[GitHub](https://github.com/faust-streaming/faust) · [PyPI](https://pypi.org/project/faust-streaming) · [Docs](https://faust-streaming.github.io/faust/)

Processes streams in Python as a fork of Faust.

- Downloads / mo: 288.1K
- Stars: 1.9K
- Last release: 0.15.4
- License: BSD-3-Clause
- Capabilities: [From the faust-streaming docs](https://faust-streaming.github.io/faust/)

```sh
pip install faust-streaming
```

**Quickstart**

```python
import faust

app = faust.App(
    'hello-world',
    broker='kafka://localhost:9092',
    value_serializer='raw',
)

greetings_topic = app.topic('greetings')

@app.agent(greetings_topic)
async def greet(greetings):
    async for greeting in greetings:
        print(greeting)

```

From [hello_world.py](https://faust-streaming.github.io/faust/playbooks/quickstart.html) · [Find projects using faust-streaming →](https://dashboard.exa.ai/playground/search?q=faust-streaming%20GitHub%20projects)

### Quix Streams

[GitHub](https://github.com/quixio/quix-streams) · [PyPI](https://pypi.org/project/quixstreams) · [Docs](https://quix.io/docs/quix-streams/)

Builds stateful stream-processing pipelines and Kafka producer-consumer applications in Python.

- Downloads / mo: 86.3K
- Stars: 1.6K
- Last release: 3.28.1
- License: Apache-2.0
- Capabilities: [From the Quix Streams docs](https://quix.io/docs/quix-streams/)

**Strengths**

- **Builds streaming dataframe pipelines.** Transform, filter, and publish Kafka messages through dataframe operations.
- **Persists state across application restarts.** Keep keyed application state locally with Kafka changelog backups.

**Watch out for**

- **State stays scoped by key.** Read or update keyed state only while processing that same message key.
- **Exactly-once processing needs configuration.** Select exactly-once explicitly when the default at-least-once behavior does not fit.

```sh
python -m pip install quixstreams
```

**Quickstart**

```python
from quixstreams import Application

app = Application(broker_address="localhost:9092")
topic = app.topic("input")

with app.get_producer() as producer:
    producer.produce(topic=topic.name, key=b"key", value=b"value")

```

From [README.md](https://github.com/quixio/quix-streams/blob/c1b0d4550ea31ec8284b119a9c241cecdaacefc5/quixstreams/app.py) · [Find projects using Quix Streams →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20quixstreams%20for%20Kafka%20offset%20commits%2C%20partition%20reassignment%2C%20batch%20publishing%20and%20event-delivery%20callbacks&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### Arroyo

[GitHub](https://github.com/getsentry/arroyo) · [PyPI](https://pypi.org/project/sentry-arroyo) · [Docs](https://getsentry.github.io/arroyo/)

Works with streaming data in Python.

- Downloads / mo: 26.4K
- Stars: 63
- Last release: 2.49.2
- License: Apache-2.0
- Capabilities: [From the Arroyo docs](https://getsentry.github.io/arroyo/)

```sh
pip install sentry-arroyo
```

**Quickstart**

```python
from arroyo.backends.kafka.configuration import (
    build_kafka_consumer_configuration,
)
from arroyo.backends.kafka.consumer import KafkaConsumer
from arroyo.types import Topic

TOPIC = Topic("source-topic")

consumer = KafkaConsumer(
    build_kafka_consumer_configuration(
        default_config={},
        bootstrap_servers=["127.0.0.1:9092"],
        auto_offset_reset="latest",
        group_id="test-group",
    )
)

consumer.subscribe([TOPIC])

while True:
    msg = consumer.poll(timeout=1.0)
    if msg is not None:
        print(f"MSG: {msg.payload}")

```

From [getstarted.rst](https://getsentry.github.io/arroyo/getstarted.html) · [Find projects using Arroyo →](https://dashboard.exa.ai/playground/search?q=sentry-arroyo%20GitHub%20projects)

### PyKafka

[GitHub](https://github.com/Parsely/pykafka) · [PyPI](https://pypi.org/project/pykafka) · [Docs](https://pykafka.readthedocs.io/en/latest/)

Implements a Kafka client in pure Python.

- Downloads / mo: 16.8K
- Stars: 1.1K
- Last release: 2.8.0
- License: Apache-2.0
- Capabilities: [From the PyKafka docs](https://pykafka.readthedocs.io/en/latest/)

```sh
pip install pykafka
```

**Quickstart**

```python
from pykafka import KafkaClient
client = KafkaClient(hosts="127.0.0.1:9092,127.0.0.1:9093,...")

client.topics

```

From [README.rst](https://github.com/Parsely/pykafka/blob/master/README.rst) · [Find projects using PyKafka →](https://dashboard.exa.ai/playground/search?q=pykafka%20GitHub%20projects)

## FAQ

### Which Python Kafka library should I use?

[confluent-kafka](#confluent-kafka) suits most production services, with producer, consumer, and administration APIs backed by librdkafka. [aiokafka](#aiokafka) suits asyncio applications. [kafka-python](#kafka-python) suits environments that need a pure Python client.

### What is the Confluent Kafka Python client?

[confluent-kafka](#confluent-kafka) is a Python client for Kafka with producer, consumer, and administration APIs backed by librdkafka. Its AIOProducer offers awaitable calls for asyncio code.

### What is FastStream?

[FastStream](#faststream) is a typed Python client for Kafka, RabbitMQ, NATS, Redis, and MQTT with awaitable publishing and subscription handlers. Its default Kafka module runs on aiokafka.

### What is kafka-python?

[kafka-python](#kafka-python) is a Kafka client written in pure Python with producer, consumer, and administration APIs. Its public API is synchronous and blocking.

### How do I consume Kafka messages in Python?

A consumer subscribes to topics and polls for messages in a loop. [confluent-kafka](#confluent-kafka) and [kafka-python](#kafka-python) offer blocking consumers. [aiokafka](#aiokafka) offers the same pattern as an asyncio consumer.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python Kafka libraries kafka-python confluent-kafka aiokafka Quix Streams producer consumer code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
