Skip to content

Examples#

Index > Kafka > Examples

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

Client#

Implicit type annotations#

Can be used with types-boto3[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 types-boto3-lite[kafka] or a standalone types_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 types_boto3_kafka.client import KafkaClient
from types_boto3_kafka.type_defs import BatchAssociateScramSecretResponseTypeDef
from types_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 types_boto3_kafka.client import KafkaClient
from types_boto3_kafka.paginator import ListClientVpcConnectionsPaginator
from types_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)