kafka-python implements Kafka producers, consumers, and admin clients without native extensions. It installs via pip, supports Python 3.8+, and includes CLI modules for quick cluster tasks.
Overview
kafka-python is a client library for Apache Kafka written entirely in Python. High-level KafkaProducer, KafkaConsumer, and KafkaAdminClient classes cover produce, consume, and administrative workflows, with optional crc32c for faster checksumming.
Consumers support consumer groups, manual partition assignment, serializers for keys and values, and cooperative rebalance features from recent Kafka improvement proposals. Admin functionality is also exposed through kafka-python admin and python -m kafka.admin for users without a local JVM toolchain.
Version 3.0 regenerated protocol code from upstream Kafka message schemas, expanded networking with asyncio-style loops, and raised the minimum Python version to 3.8.
Examples in the documentation show iterating messages, subscribing to topics, and configuring bootstrap servers for local brokers.
Key features
- KafkaProducer and KafkaConsumer APIs
- KafkaAdminClient for cluster management
- Pure Python without Cython dependencies
- Optional crc32c performance dependency
- CLI admin, producer, and consumer modules
- Consumer group and manual assign support
- Key and value deserializer helpers
Use cases
- Stream processing prototypes in Python
- Administer Kafka without Java bin scripts
- Integrate services with existing Python stacks