Python asyncio producer and consumer for Kafka brokers. It mirrors the Java client style with coordinated consumer groups and optional compression extras.
Overview
aiokafka is a Python client for Apache Kafka built on asyncio. It reuses internals from kafka-python for protocol parsing and errors while exposing async producer and consumer APIs.
AIOKafkaProducer sends messages asynchronously after contacting the cluster for metadata. AIOKafkaConsumer joins consumer groups for coordinated partition assignment on brokers that support modern group protocols, then iterates messages with standard topic, partition, offset, key, value, and timestamp fields.
The client supports Kafka 1.0 and newer brokers with fully coordinated consumer groups. Installation is via pip, with optional extras for LZ4, Snappy, zstd, and GSSAPI authentication where platform build tools are required.
Documentation covers producer buffering, retries, idempotent and transactional produce, offset management, rebalance listeners, SSL and SASL setup, metrics, and differences from kafka-python such as background rebalances and prefetch behavior.
Key features
- Async Kafka producer client
- Async consumer with group support
- Java-like client semantics
- Optional LZ4 Snappy zstd compression
- SASL GSSAPI authentication extra
- SSL context helpers
- Transactional and idempotent produce
- Prometheus metrics examples
Use cases
- Async Python Kafka producers
- Coordinated consumer group workers
- Event streaming in asyncio services
- Migrating from kafka-python patterns