Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
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
confluent-kafka has the most monthly downloads in this comparison, at 46.4M.
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())
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,
)
aiokafka
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
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.
Limitations
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.
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 pykafka import KafkaClient
client = KafkaClient(hosts="127.0.0.1:9092,127.0.0.1:9093,...")
client.topics
FAQ
confluent-kafka suits most production services, with producer, consumer, and administration APIs backed by librdkafka. aiokafka suits asyncio applications. kafka-python suits environments that need a pure Python client.
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.
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.
kafka-python is a Kafka client written in pure Python with producer, consumer, and administration APIs. Its public API is synchronous and blocking.
A consumer subscribes to topics and polls for messages in a loop. confluent-kafka and kafka-python offer blocking consumers. aiokafka offers the same pattern as an asyncio consumer.
For coding agents
Found your kafka library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.