Skip to content

Examples#

Index > Kafka > Examples

Auto-generated documentation for Kafka type annotations stubs module mypy-boto3-kafka.

Client#

Implicit type annotations#

Can be used with boto3-stubs[kafka] package installed.

Write your Kafka code as usual, type checking and code completion should work out of the box.

# KafkaClient usage example

from boto3.session import Session


session = Session()

client = session.client("kafka")  # (1)
result = client.batch_associate_scram_secret()  # (2)
  1. client: KafkaClient
  2. result: BatchAssociateScramSecretResponseTypeDef
# ListClientVpcConnectionsPaginator usage example

from boto3.session import Session


session = Session()
client = session.client("kafka")  # (1)

paginator = client.get_paginator("list_client_vpc_connections")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: KafkaClient
  2. paginator: ListClientVpcConnectionsPaginator
  3. item: ListClientVpcConnectionsResponseTypeDef

Explicit type annotations#

With boto3-stubs-lite[kafka] or a standalone mypy_boto3_kafka package, you have to explicitly specify client: KafkaClient type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

# KafkaClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_kafka.client import KafkaClient
from mypy_boto3_kafka.type_defs import BatchAssociateScramSecretResponseTypeDef
from mypy_boto3_kafka.type_defs import BatchAssociateScramSecretRequestRequestTypeDef


session = Session()

client: KafkaClient = session.client("kafka")

kwargs: BatchAssociateScramSecretRequestRequestTypeDef = {...}
result: BatchAssociateScramSecretResponseTypeDef = client.batch_associate_scram_secret(**kwargs)
# ListClientVpcConnectionsPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_kafka.client import KafkaClient
from mypy_boto3_kafka.paginator import ListClientVpcConnectionsPaginator
from mypy_boto3_kafka.type_defs import ListClientVpcConnectionsResponseTypeDef


session = Session()
client: KafkaClient = session.client("kafka")

paginator: ListClientVpcConnectionsPaginator = client.get_paginator("list_client_vpc_connections")
for item in paginator.paginate(...):
    item: ListClientVpcConnectionsResponseTypeDef
    print(item)