PyKafka is a Python library for interacting with Apache Kafka using the confluent-kafka library. With PyKafka, you can easily produce and consume messages from Kafka topics.
To install PyKafka, run the following command:
pip install -r requirements.txt
The requirements file, requirements.txt, should include the following:
confluent-kafka
Here is an example of how to use PyKafka to produce and consume messages:
from PyKafka import PyKafka
# Initialize PyKafka with a broker URL and group ID
kafka = PyKafka('localhost:9092', 'example-group')
# Produce a message to a topic
kafka.produce('example-topic', 'key', 'value')
# Consume messages from a topic
for key, value in kafka.consume('example-topic'):
print(key, value)
If you would like to contribute to PyKafka, please fork the repository and make a pull request.