Command-Line Interface
kafka-python ships simple command-line interfaces for consumer, producer,
and admin clients. They can be invoked either as the kafka-python
console script or as module entry points:
kafka-python consumer -b localhost:9092 -t my-topic
kafka-python producer -b localhost:9092 -t my-topic
kafka-python admin -b localhost:9092 cluster describe
# equivalent module invocations
python -m kafka.consumer -b localhost:9092 -t my-topic
python -m kafka.producer -b localhost:9092 -t my-topic
python -m kafka.admin -b localhost:9092 cluster describe
The kafka-python admin command, in particular, is a convenient
alternative to the apache kafka bin/ scripts when a compatible JVM is
not available.
Common Options
All three commands share a common set of connection, logging, and configuration options. They are documented in full on the individual command pages; the summary below highlights the most commonly used flags.
Connection
-b/--bootstrap-servers HOST:PORTOne or more bootstrap servers used to discover the rest of the cluster. May be supplied multiple times.
-S/--security-protocolOne of
PLAINTEXT,SSL,SASL_PLAINTEXT,SASL_SSL. Defaults toPLAINTEXT.-M/--sasl-mechanismOne of
PLAIN,GSSAPI,OAUTHBEARER,SCRAM-SHA-256,SCRAM-SHA-512. Defaults toPLAIN.-U/--sasl-user/-P/--sasl-passwordCredentials for SASL
PLAINandSCRAM-*mechanisms.
Logging
-l/--log-levelPython
logginglevel (DEBUG,INFO, …). Defaults toCRITICALso the CLI is quiet by default.-L/--enable-logger/-D/--disable-loggerSelectively turn on or off a single logger by name. Both flags may be supplied multiple times.
Extended Configuration
-C/--extra-config key=valuePass arbitrary keyword arguments through to the underlying client constructor (
KafkaConsumer,KafkaProducer, orKafkaAdminClient). Values that parse asint,True,False, orNoneare converted; everything else is passed through as a string. May be supplied multiple times.kafka-python consumer -b localhost:9092 -t foo \ -C auto_offset_reset=earliest \ -C consumer_timeout_ms=1000