Skip to content

Examples#

Index > Bedrock > Examples

Auto-generated documentation for Bedrock type annotations stubs module mypy-boto3-bedrock.

Client#

Implicit type annotations#

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

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

# BedrockClient usage example

from boto3.session import Session


session = Session()

client = session.client("bedrock")  # (1)
result = client.batch_delete_evaluation_job()  # (2)
  1. client: BedrockClient
  2. result: BatchDeleteEvaluationJobResponseTypeDef
# ListCustomModelsPaginator usage example

from boto3.session import Session


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

paginator = client.get_paginator("list_custom_models")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: BedrockClient
  2. paginator: ListCustomModelsPaginator
  3. item: ListCustomModelsResponseTypeDef

Explicit type annotations#

With boto3-stubs-lite[bedrock] or a standalone mypy_boto3_bedrock package, you have to explicitly specify client: BedrockClient 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.

# BedrockClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_bedrock.client import BedrockClient
from mypy_boto3_bedrock.type_defs import BatchDeleteEvaluationJobResponseTypeDef
from mypy_boto3_bedrock.type_defs import BatchDeleteEvaluationJobRequestRequestTypeDef


session = Session()

client: BedrockClient = session.client("bedrock")

kwargs: BatchDeleteEvaluationJobRequestRequestTypeDef = {...}
result: BatchDeleteEvaluationJobResponseTypeDef = client.batch_delete_evaluation_job(**kwargs)
# ListCustomModelsPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_bedrock.client import BedrockClient
from mypy_boto3_bedrock.paginator import ListCustomModelsPaginator
from mypy_boto3_bedrock.type_defs import ListCustomModelsResponseTypeDef


session = Session()
client: BedrockClient = session.client("bedrock")

paginator: ListCustomModelsPaginator = client.get_paginator("list_custom_models")
for item in paginator.paginate(...):
    item: ListCustomModelsResponseTypeDef
    print(item)