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, an int, a float, a str, or, for a list property, a list or tuple. A str is accepted for every property.

  • To use a property’s default, leave it out of the dict. None raises ConfigError for most properties, such as linger.ms and acks. A few, such as client.id, accept None and 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 INFO level:

    These configurations '[...]' were supplied but are not used yet.

    The Python Client writes its log to standard error, and shows INFO lines only when the RUST_LOG environment variable is set to info.

  • 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

group.protocol

Optional. classic or consumer. Default: classic.

Required for the consumer. Set to consumer. If it isn’t set, or is set to classic, creating the consumer raises UnsupportedOperationError.

isolation.level

Default: read_uncommitted.

Default: read_committed. Set to read_uncommitted for the same behavior as the Java Client.

partitioner.type

Doesn’t exist. The Java Client sets the partitioner with partitioner.class. When partitioner.class isn’t set, the built-in partitioner hashes the record key with murmur2.

Selects a built-in partitioner:

  • ConsistentRandomPartitioner: Default. The built-in partitioner with a CRC-32 key hash, as in Python Client 2.x.

  • Murmur2RandomPartitioner: The built-in partitioner with a murmur2 key hash. It’s the partitioner the Java Client uses by default, when partitioner.class isn’t set.

  • RoundRobinPartitioner: Spreads records evenly across partitions and ignores the key. It turns off adaptive partitioning.

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 Murmur2RandomPartitioner when Java producers write to the same topic.

key.serializer, value.serializer, key.deserializer, value.deserializer

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 mypackage.serdes.MySerializer. The class must be defined at the top level of its module. The client creates the serializer or deserializer with no arguments and calls its configure(configs, is_key) method, if the method exists. A serializer or deserializer passed to the constructor takes precedence. Without a serializer or deserializer, the Python Client uses the bytes serializer or deserializer.

sasl.mechanism

Default: GSSAPI. Also PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, and OAUTHBEARER.

PLAIN only. When security.protocol is SASL_PLAINTEXT or SASL_SSL, set sasl.mechanism=PLAIN. Any other value, including the default, raises ConfigError. Set the username and password in sasl.jaas.config.

ssl.keystore.type, ssl.truststore.type

Default: JKS. Also PKCS12 and PEM.

Default: PEM. Other store types aren’t supported. If security.protocol is SSL or SASL_SSL and the store type isn’t PEM, creating the client raises KafkaError, with a ConfigError as its __cause__. Give the PEM data as files, such as ssl.keystore.location or ssl.truststore.location, or inline, such as ssl.keystore.key, ssl.keystore.certificate.chain, or ssl.truststore.certificates. A keystore file holds the private key and its certificate chain.

Unsupported properties

The Python Client doesn’t support the following Java Client properties. The client accepts them but ignores them.

Property

Notes

partitioner.class

Use partitioner.type.

interceptor.classes

metric.reporters

Read the metrics with the client’s metrics() method.

enable.metrics.push

config.providers

A value such as ${file:/path:key} is used as written. Read the value in your application and put it in the dict.

ssl.key.password, ssl.keystore.password, ssl.truststore.password

If the private key is encrypted, creating the client raises KafkaError, with a ConfigError as its __cause__. Use an unencrypted PKCS#8 private key.

security.providers, ssl.engine.factory.class, ssl.provider, ssl.secure.random.implementation, ssl.keymanager.algorithm, ssl.trustmanager.algorithm

The client has built-in TLS. Without ssl.truststore.location or ssl.truststore.certificates, it trusts Mozilla’s root certificates.

sasl.client.callback.handler.class, sasl.login.*, sasl.kerberos.*, sasl.oauthbearer.*

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.