You need to install kafka on your machine and launch it in order to use the code For further details follow this link https://kafka.apache.org/documentation/#quickstart
To install the confluent_kafka library for Python, use the following command:
pip install confluent-kafka
Alternatively, you can consider using other libraries like pykafka as an alternative.
confluent_kafka provides better performance, whereas pykafka is better suited for use with Python You can find more details in this link below : https://matthewrocklin.com/blog/work/2017/10/10/kafka-python#:~:text=Both%20PyKafka%20and%20confluent%2Dkafka,and%20documented%20for%20Python%20usability.