Configure Python Client 4.4
Python Client 4.4 uses the configuration properties of the Java Client. A property has the same name, type, default, and meaning as in the Java Client 4.4, except for the properties in Differences from the Java Client. For the full list of properties, see:
Python Client 4.4 doesn’t support the share consumer (Queues for Kafka, KIP-932), so
the share consumer properties, such as share.acknowledgement.mode, don’t
apply.
Note
The 4.4 Python Client is a Preview release.
A Preview feature is a Python client component that is being introduced to gain early feedback from developers. Preview features can be used for evaluation and non-production testing purposes or to provide feedback to Confluent. The warranty, SLA, and Support Services provisions of your agreement with Confluent do not apply to Preview features. Confluent may discontinue providing preview releases of the Preview features at any time in Confluent’s’ sole discretion.
If you are migrating from Python Client 2.x, which uses librdkafka property names, see Migration guide: Configuration changes.
Pass the configuration
Pass the configuration as a dict in the configs argument of the client
constructor, or of Admin.create(). The keys are the Java Client property names.
The ProducerConfig, ConsumerConfig, and AdminClientConfig classes
hold the names as constants:
from confluent_kafka.producer import KafkaProducer, ProducerConfig
producer = KafkaProducer(configs={
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG: 'localhost:9092',
ProducerConfig.LINGER_MS_CONFIG: 10,
ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG: True,
})
The client checks the configuration when you create it. An invalid key or value
raises ConfigError from confluent_kafka.common.config with a message:
A key must be a
str.A value is a
bool, anint, afloat, astr, or, for a list property, alistortuple. Astris accepted for every property.To use a property’s default, leave it out of the
dict.NoneraisesConfigErrorfor most properties, such aslinger.msandacks. A few, such asclient.id, acceptNoneand leave the property unset.A property that the client doesn’t recognize isn’t an error. The client ignores it and logs its name at
INFOlevel:These configurations '[...]' were supplied but are not used yet.The Python Client writes its log to standard error, and shows
INFOlines only when theRUST_LOGenvironment variable is set toinfo.No property takes a callback. A failed operation raises an error or fails its future.
Differences from the Java Client
The Python Client differs from the Java Client in some defaults and values, and doesn’t support some properties. Make sure your application works with these differences.
Properties with different defaults or values
Property |
Java Client |
Python Client 4.4 |
|---|---|---|
|
Optional. |
Required for the consumer. Set to |
|
Default: |
Default: |
|
Doesn’t exist. The Java Client sets the partitioner with
|
Selects a built-in partitioner:
By default, a record with a key goes to the same partition as with
Python Client 2.x, not to the partition the Java Client chooses. Set
|
|
The name of a Java class. Required, unless a serializer or deserializer is passed to the constructor. |
Optional. A Python class, or its fully qualified name, such as
|
|
Default: |
|
|
Default: |
Default: |
Unsupported properties
The Python Client doesn’t support the following Java Client properties. The client accepts them but ignores them.
Property |
Notes |
|---|---|
|
Use |
|
|
|
Read the metrics with the client’s |
|
|
|
A value such as |
|
If the private key is encrypted, creating the client raises
|
|
The client has built-in TLS. Without |
|
SASL/GSSAPI, SASL/OAUTHBEARER, and custom login and callback handlers aren’t supported. For authentication, use SASL/PLAIN, or TLS with a client certificate in the keystore. |