confluent_kafka.common.header

confluent_kafka.common.header: Java’s org.apache.kafka.common.header.

One file per class; import the classes from this module, never from the files (CLAUDE.md, Python Binding Conventions, Modules).

Headers

class confluent_kafka.common.header.Headers[source]
class confluent_kafka.common.header.Headers(*, headers: tuple[Header, ...] | None)
class confluent_kafka.common.header.Headers(*, headers: Iterable[Header | tuple[str, bytes | bytearray | memoryview | None]] | None)

Bases: object

The headers of a record: an ordered list of Header s, in which a key may repeat.

Java: org.apache.kafka.common.header.Headers, implemented by org.apache.kafka.common.header.internals.RecordHeaders.

add(*, header: Header) → Headers[source]
add(*, key: str, value: bytes | bytearray | memoryview | None) → Headers

Adds a header (key inside), to the end, returning the headers, so calls can be chained: add(header=…), or add(key=…, value=…), which creates the header from the key and value (None is allowed for the value). Raises IllegalStateError if the headers are in a read-only state, and TypeError for a None header or key, as Java’s Objects.requireNonNull.

remove(*, key: str) → Headers[source]

Removes all headers for the given key, returning the headers, so calls can be chained. Raises IllegalStateError if the headers are in a read-only state, and IllegalArgumentError for a None key.

last_header(*, key: str) → Header | None[source]

Returns just one (the very last) header for the given key, if present, else None. Raises IllegalArgumentError for a None key.

headers(*, key: str) → list[Header][source]

Returns all headers for the given key, in the order they were added in. Raises IllegalArgumentError for a None key.

to_array() → tuple[Header, ...][source]

Returns all headers as an array, in the order they were added in.