confluent_kafka.common¶
confluent_kafka.common: Java’s org.apache.kafka.common.
The value types of org.apache.kafka.common (TopicPartition, Uuid,
Node, KafkaFuture, …) and its errors (KafkaError,
InvalidRecordError). Every common.* subpackage is a module of its own,
holding the types of that Java package (CLAUDE.md, Python Binding Conventions,
Modules): common.acl, common.config, common.errors, common.header,
common.metrics, common.network, common.protocol.types, common.quota,
common.record, common.requests, common.resource,
common.security.auth, common.security.token.delegation and
common.serialization.
AsyncKafkaFuture¶
- class confluent_kafka.common.AsyncKafkaFuture(*args: Any, **kwargs: Any)[source]¶
Bases:
_KafkaFutureBase[T]The asyncio peer of
KafkaFuture: the future an asyncio class hands out.get()is awaited; the inner future is anasyncio.Futureon the client’s event loop, and a cancelled future raisesasyncio.CancelledError.Java:
org.apache.kafka.common.KafkaFuture.- BaseFunction: TypeAlias¶
A function which takes objects of type A and returns objects of type B.
alias of
Callable[[_A],_B]
- BiConsumer: TypeAlias¶
A consumer of two different types of object.
alias of
Callable[[_A,_B],None]
- static completed_future(*, value: U) AsyncKafkaFuture[U][source]¶
Returns a new AsyncKafkaFuture that is already completed with the given value.
- static all_of(*, futures: tuple[AsyncKafkaFuture[Any], ...]) AsyncKafkaFuture[None][source]¶
Returns a new AsyncKafkaFuture that is completed when all the given futures have completed. If any future fails, the returned future fails with it. If multiple futures fail, the first failure is returned. A
Nonefutures, or aNoneamong them, raisesTypeError, as Java’sArrays.stream(null)andkafkaFuture.toCompletionStage()do.
- to_completion_stage() Future[T][source]¶
Gets the inner
asyncio.Futurethis future waits on, on the client’s event loop (or the running loop), which completes when this future completes and in the same way.
- then_apply(*, function: Callable[[T], R]) AsyncKafkaFuture[R][source]¶
Returns a new AsyncKafkaFuture that, when this future completes normally, is executed with this future’s result as the argument to the supplied function.
The function runs where this future completes (the event loop of an asyncio client), or inside this call when the future is already done.
- when_complete(*, action: Callable[[T | None, BaseException | None], None]) AsyncKafkaFuture[T][source]¶
Returns a new AsyncKafkaFuture with the same result or error as this future, that executes the given action when this future completes; see
KafkaFuture.when_complete().
- cancel(*, may_interrupt_if_running: bool) bool[source]¶
If not already completed, completes this future with an
asyncio.CancelledError. Dependent futures that have not already completed will also be cancelled. Never cancels the source, the request or the core.
- async get() T[source]¶
- async get(*, timeout: Duration) T
Waits if necessary for this future to complete, and then returns its result; with
timeout, for at most that long, raisingconfluent_kafka.TimeoutErrorwhen it elapses first (a negative or zero timeout raises at once unless the future is done). ANonetimeout raisesTypeError, as Java’s nullTimeUnitdoes.A failed future raises
confluent_kafka.ExecutionErrorfrom the failure; a cancelled oneasyncio.CancelledError. Cancelling the awaiting task does not cancel the future.
- get_now(*, value_if_absent: T) T[source]¶
Returns the result value (or raises any encountered error) if completed, else returns the given
value_if_absent.
- is_cancelled() bool[source]¶
Returns true if this future was cancelled before it completed normally.
ClassicGroupState¶
- class confluent_kafka.common.ClassicGroupState(*values)[source]¶
Bases:
EnumThe classic group state.
Java:
org.apache.kafka.common.ClassicGroupState.- UNKNOWN = 'UNKNOWN'¶
- PREPARING_REBALANCE = 'PREPARING_REBALANCE'¶
- COMPLETING_REBALANCE = 'COMPLETING_REBALANCE'¶
- STABLE = 'STABLE'¶
- DEAD = 'DEAD'¶
- EMPTY = 'EMPTY'¶
- static parse(*, name: str) ClassicGroupState[source]¶
Case-insensitive classic group state lookup by string name.
Cluster¶
- confluent_kafka.common.Cluster¶
alias of
object
ElectionType¶
- class confluent_kafka.common.ElectionType(*values)[source]¶
Bases:
IntEnumOptions for
Admin.elect_leaders.Java:
org.apache.kafka.common.ElectionType.- PREFERRED = 0¶
- UNCLEAN = 1¶
- static value_of(*, value: int) ElectionType[source]¶
The election type whose
valueisvalue;IllegalArgumentErrorwhen there is none.
GroupState¶
- class confluent_kafka.common.GroupState(*values)[source]¶
Bases:
EnumThe group state.
The correspondence between the group states and types:
State
Classic
Consumer
Share
Streams
UNKNOWN
Yes
Yes
Yes
Yes
PREPARING_REBALANCE
Yes
Yes
COMPLETING_REBALANCE
Yes
Yes
STABLE
Yes
Yes
Yes
Yes
DEAD
Yes
Yes
Yes
Yes
EMPTY
Yes
Yes
Yes
Yes
ASSIGNING
Yes
Yes
RECONCILING
Yes
Yes
NOT_READY
Yes
Java:
org.apache.kafka.common.GroupState.- UNKNOWN = 'UNKNOWN'¶
- PREPARING_REBALANCE = 'PREPARING_REBALANCE'¶
- COMPLETING_REBALANCE = 'COMPLETING_REBALANCE'¶
- STABLE = 'STABLE'¶
- DEAD = 'DEAD'¶
- EMPTY = 'EMPTY'¶
- ASSIGNING = 'ASSIGNING'¶
- RECONCILING = 'RECONCILING'¶
- NOT_READY = 'NOT_READY'¶
- static parse(*, name: str) GroupState[source]¶
Case-insensitive group state lookup by string name.
- static group_states_for_type(*, type: GroupType) set[GroupState][source]¶
The states a group of
typecan be in;IllegalArgumentErrorforGroupType.UNKNOWN.
GroupType¶
IsolationLevel¶
- class confluent_kafka.common.IsolationLevel(*values)[source]¶
Bases:
IntEnumThe isolation level of a read.
Java:
org.apache.kafka.common.IsolationLevel.- READ_UNCOMMITTED = 0¶
- READ_COMMITTED = 1¶
- static for_id(*, id: int) IsolationLevel[source]¶
The isolation level whose id is
id;IllegalArgumentErrorwhen there is none.
KafkaFuture¶
- class confluent_kafka.common.KafkaFuture(*args: Any, **kwargs: Any)[source]¶
Bases:
_KafkaFutureBase[T]A flexible future which supports call chaining and other asynchronous programming patterns.
It is possible to obtain the inner
concurrent.futures.Futurefrom aKafkaFutureby callingto_completion_stage(). A failedKafkaFutureraisesExecutionErrorfromget(), with the failure as its__cause__, whereas the inner future raises the failure itself.Java:
org.apache.kafka.common.KafkaFuture.- BaseFunction: TypeAlias¶
A function which takes objects of type A and returns objects of type B.
alias of
Callable[[_A],_B]
- BiConsumer: TypeAlias¶
A consumer of two different types of object.
alias of
Callable[[_A,_B],None]
- static completed_future(*, value: U) KafkaFuture[U][source]¶
Returns a new KafkaFuture that is already completed with the given value.
- static all_of(*, futures: tuple[KafkaFuture[Any], ...]) KafkaFuture[None][source]¶
Returns a new KafkaFuture that is completed when all the given futures have completed. If any future fails, the returned future fails with it. If multiple futures fail, the first failure is returned. A
Nonefutures, or aNoneamong them, raisesTypeError, as Java’sArrays.stream(null)andkafkaFuture.toCompletionStage()do.
- to_completion_stage() Future[T][source]¶
Gets the inner
concurrent.futures.Futurethis future waits on, which completes when this future completes and in the same way (with the same result or error, or cancelled).To wait for a KafkaFuture use
get()orget_now(), rather than the inner future’sresult().
- then_apply(*, function: Callable[[T], R]) KafkaFuture[R][source]¶
Returns a new KafkaFuture that, when this future completes normally, is executed with this future’s result as the argument to the supplied function.
The function runs where this future completes (the producer’s completion thread, the admin client’s pump thread), or inside this call when the future is already done.
- when_complete(*, action: Callable[[T | None, BaseException | None], None]) KafkaFuture[T][source]¶
Returns a new KafkaFuture with the same result or error as this future, that executes the given action when this future completes.
When this future is done, the given action is invoked with the result (or
Noneif none) and the error (orNoneif none) of this future as arguments. The returned future is completed when the action returns. The supplied action should not raise. However, if it does, the following rules apply: if this future completed normally but the supplied action raises, then the returned future fails with the action’s error. Or, if this future failed and the supplied action raises, then the returned future fails with this future’s error.The action runs where this future completes, or inside this call when the future is already done.
- cancel(*, may_interrupt_if_running: bool) bool[source]¶
If not already completed, completes this future with a
concurrent.futures.CancelledError. Dependent futures that have not already completed will also be cancelled. Never cancels the source, the request or the core.
- get() T[source]¶
- get(*, timeout: Duration) T
Waits if necessary for this future to complete, and then returns its result; with
timeout, for at most that long, raisingconfluent_kafka.TimeoutErrorwhen it elapses first (a negative or zero timeout raises at once unless the future is done). ANonetimeout raisesTypeError, as Java’s nullTimeUnitdoes.A failed future raises
confluent_kafka.ExecutionErrorfrom the failure; a cancelled oneconcurrent.futures.CancelledError. The wait is in short slices, so Ctrl+C ends it.
- get_now(*, value_if_absent: T) T[source]¶
Returns the result value (or raises any encountered error) if completed, else returns the given
value_if_absent.
- is_cancelled() bool[source]¶
Returns true if this future was cancelled before it completed normally.
Metric¶
- class confluent_kafka.common.Metric[source]¶
Bases:
ProtocolA metric tracked for monitoring purposes.
Java:
org.apache.kafka.common.Metric.- metric_name() MetricName[source]¶
A name for this metric.
MetricName¶
- class confluent_kafka.common.MetricName(*, name: str, group: str, description: str, tags: Mapping[str, str])[source]¶
Bases:
objectThe
MetricNameclass encapsulates a metric’s name, logical group and its related attributes.name: the name of the metric;group: logical group name of the metrics to which this metric belongs;description: a human-readable description to include in the metric;tags: additional key/value attributes of the metric.
groupandtagscan be used to create unique metric names while reporting in JMX or any custom reporting. Equality and the hash are overgroup,nameandtags.Java:
org.apache.kafka.common.MetricName(final).
Node¶
- class confluent_kafka.common.Node(*, id: int, host: str, port: int)[source]¶
- class confluent_kafka.common.Node(*, id: int, host: str, port: int, rack: str | None)
- class confluent_kafka.common.Node(*, id: int, host: str, port: int, rack: str | None, is_fenced: bool)
Bases:
objectInformation about a Kafka node.
Java:
org.apache.kafka.common.Node.- is_empty() bool[source]¶
Check whether this node is empty, which may be the case if
no_node()is used as a placeholder in a response payload with an error.
PartitionInfo¶
- class confluent_kafka.common.PartitionInfo(*, topic: str, partition: int, leader: Node | None, replicas: tuple[Node, ...], in_sync_replicas: tuple[Node, ...])[source]¶
- class confluent_kafka.common.PartitionInfo(*, topic: str, partition: int, leader: Node | None, replicas: tuple[Node, ...], in_sync_replicas: tuple[Node, ...], offline_replicas: tuple[Node, ...])
Bases:
objectThis is used to describe per-partition state in the MetadataResponse.
Java:
org.apache.kafka.common.PartitionInfo.- leader() Node | None[source]¶
The node id of the node currently acting as a leader for this partition or
Noneif there is no leader.
- replicas() tuple[Node, ...][source]¶
The complete set of replicas for this partition regardless of whether they are alive or up-to-date. The preferred replica is the head of the list.
TopicCollection¶
- class confluent_kafka.common.TopicCollection(*args: Any, **kwargs: Any)[source]¶
Bases:
objectA class used to represent a collection of topics. This collection may define topics by name or ID.
Java:
org.apache.kafka.common.TopicCollection.- class TopicIdCollection(*args: Any, **kwargs: Any)¶
Bases:
TopicCollectionA class used to represent a collection of topics defined by their topic ID. Subclassing this class beyond the classes provided here is not supported.
Java:
org.apache.kafka.common.TopicCollection.TopicIdCollection.
- class TopicNameCollection(*args: Any, **kwargs: Any)¶
Bases:
TopicCollectionA class used to represent a collection of topics defined by their topic name. Subclassing this class beyond the classes provided here is not supported.
Java:
org.apache.kafka.common.TopicCollection.TopicNameCollection.- topic_names() list[str]¶
A collection of topic names.
- static of_topic_ids(*, topics: Iterable[Uuid]) TopicIdCollection[source]¶
A collection of topics defined by topic ID.
- static of_topic_names(*, topics: Iterable[str]) TopicNameCollection[source]¶
A collection of topics defined by topic name.
TopicIdPartition¶
- class confluent_kafka.common.TopicIdPartition(*, topic_id: Uuid, topic_partition: TopicPartition)[source]¶
- class confluent_kafka.common.TopicIdPartition(*, topic_id: Uuid, partition: int, topic: str | None)
Bases:
objectThis represents universally unique identifier with topic id for a topic partition. This makes sure that topics recreated with the same name will always have unique topic identifiers.
Java:
org.apache.kafka.common.TopicIdPartition.- topic_partition() TopicPartition[source]¶
Topic partition representing this instance.
TopicPartition¶
TopicPartitionInfo¶
- class confluent_kafka.common.TopicPartitionInfo(*, partition: int, leader: Node | None, replicas: Sequence[Node], isr: Sequence[Node], elr: Sequence[Node], last_known_elr: Sequence[Node])[source]¶
- class confluent_kafka.common.TopicPartitionInfo(*, partition: int, leader: Node | None, replicas: Sequence[Node], isr: Sequence[Node])
Bases:
objectA class containing leadership, replicas and ISR information for a topic partition.
Java:
org.apache.kafka.common.TopicPartitionInfo.- replicas() list[Node][source]¶
Return the replicas of the partition in the same order as the replica assignment. The preferred replica is the head of the list.
Brokers with version lower than 0.11.0.0 return the replicas in unspecified order due to a bug.
- isr() list[Node][source]¶
Return the in-sync replicas of the partition. Note that the ordering of the result is unspecified.
TopicPartitionReplica¶
Uuid¶
- class confluent_kafka.common.Uuid(*, most_sig_bits: int, least_sig_bits: int)[source]¶
Bases:
objectThis class defines an immutable universally unique identifier (UUID). It represents a 128-bit value. More specifically, the random UUIDs generated by this class are variant 2 (Leach-Salz) version 4 UUIDs. This is the same type of UUID as the ones generated by
java.util.UUID. The__str__method prints using the base64 string encoding. Likewise, thefrom_stringmethod expects a base64 string encoding.Java:
org.apache.kafka.common.Uuid.- ONE_UUID: ClassVar[Uuid] = <confluent_kafka.common.uuid.Uuid object>¶
A reserved UUID. Will never be returned by the
random_uuidmethod.
- METADATA_TOPIC_ID: ClassVar[Uuid] = <confluent_kafka.common.uuid.Uuid object>¶
A UUID for the metadata topic in KRaft mode. Will never be returned by the
random_uuidmethod.
- ZERO_UUID: ClassVar[Uuid] = <confluent_kafka.common.uuid.Uuid object>¶
A UUID that represents a null or empty UUID. Will never be returned by the
random_uuidmethod.
- RESERVED: ClassVar[frozenset[Uuid]] = frozenset({<confluent_kafka.common.uuid.Uuid object>, <confluent_kafka.common.uuid.Uuid object>})¶
The set of reserved UUIDs that will never be returned by the
random_uuidmethod.
- static random_uuid() Uuid[source]¶
Static factory to retrieve a type 4 (pseudo randomly generated) UUID. This will not generate a UUID equal to 0, 1, or one whose string representation contains a dash (“-“).
- static from_string(*, str: str) Uuid[source]¶
Creates a UUID based on a base64 string encoding used in the
__str__method. (stris Java’s parameter name; it shadows the builtin only inside this method, whose body does not callstr().) ANoneraisesTypeError, as Java’sstr.length().
InvalidRecordError¶
- exception confluent_kafka.common.InvalidRecordError(*, message: str | None)¶
- exception confluent_kafka.common.InvalidRecordError(*, message: str | None, cause: BaseException | None)
Bases:
InvalidConfigurationErrorJava:
org.apache.kafka.common.InvalidRecordException.
KafkaError¶
- exception confluent_kafka.common.KafkaError(*, message: str | None, cause: BaseException | None)¶
- exception confluent_kafka.common.KafkaError(*, message: str | None)
- exception confluent_kafka.common.KafkaError(*, cause: BaseException | None)
- exception confluent_kafka.common.KafkaError
Bases:
RuntimeErrorThe base class of all other Kafka exceptions
Java:
org.apache.kafka.common.KafkaException.