Skip to content

TopicPartition

faststream.kafka.TopicPartition #

TopicPartition(
    topic: str, partition: int = -1, *, declare: bool = True
)

A Kafka topic partition with its creation setting.

Initialize the Kafka topic partition.

PARAMETER DESCRIPTION
topic

Kafka topic name.

TYPE: str

partition

Partition number to assign.

TYPE: int DEFAULT: -1

declare

Whether to create the topic automatically or just connect to it. Missing topics are not created and their absence is not reported, so set it to False for topics provisioned by someone else.

TYPE: bool DEFAULT: True

Source code in faststream/kafka/schemas/partition.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def __init__(
    self,
    topic: str,
    partition: int = -1,
    *,
    declare: bool = True,
) -> None:
    """Initialize the Kafka topic partition.

    Args:
        topic: Kafka topic name.
        partition: Partition number to assign.
        declare: Whether to create the topic automatically or just connect to it.
            Missing topics are not created and their absence is not reported,
            so set it to `False` for topics provisioned by someone else.
    """
    self.topic = topic
    self.partition = partition
    self.declare = declare

topic instance-attribute #

topic = topic

partition instance-attribute #

partition = partition

declare instance-attribute #

declare = declare

add_prefix #

add_prefix(prefix: str) -> TopicPartition
Source code in faststream/kafka/schemas/partition.py
30
31
32
33
34
35
def add_prefix(self, prefix: str) -> "TopicPartition":
    return TopicPartition(
        f"{prefix}{self.topic}",
        self.partition,
        declare=self.declare,
    )