2

kafka-python contains multiple modules to create/delete topic and also pass multiple configuration while doing so.

Is there a way to add additional configuration to following method -

NewTopic(name=topicname, num_partitions=1, replication_factor=1)

krishna reddy
  • 295
  • 2
  • 15

1 Answers1

3

Yes it's possible to create a compacted topic with kafka-python.

The NewTopic constructor accepts a topic_configs argument to specify the topic configurations.

For example:

from kafka import KafkaAdminClient
from kafka.admin import NewTopic

admin = KafkaAdminClient(bootstrap_servers=['localhost:9092'])
topic = NewTopic('bar', 1, 1, topic_configs={'cleanup.policy': 'compact'})
response = admin.create_topics([topic])

print(response)
Mickael Maison
  • 25,067
  • 7
  • 71
  • 68