Skip to content

Examples#

Index > CognitoIdentity > Examples

Auto-generated documentation for CognitoIdentity type annotations stubs module mypy-boto3-cognito-identity.

Client#

Implicit type annotations#

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

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

# CognitoIdentityClient usage example

from boto3.session import Session


session = Session()

client = session.client("cognito-identity")  # (1)
result = client.create_identity_pool()  # (2)
  1. client: CognitoIdentityClient
  2. result: IdentityPoolTypeDef
# ListIdentityPoolsPaginator usage example

from boto3.session import Session


session = Session()
client = session.client("cognito-identity")  # (1)

paginator = client.get_paginator("list_identity_pools")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: CognitoIdentityClient
  2. paginator: ListIdentityPoolsPaginator
  3. item: ListIdentityPoolsResponseTypeDef

Explicit type annotations#

With boto3-stubs-lite[cognito-identity] or a standalone mypy_boto3_cognito_identity package, you have to explicitly specify client: CognitoIdentityClient 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.

# CognitoIdentityClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_cognito_identity.client import CognitoIdentityClient
from mypy_boto3_cognito_identity.type_defs import IdentityPoolTypeDef
from mypy_boto3_cognito_identity.type_defs import CreateIdentityPoolInputRequestTypeDef


session = Session()

client: CognitoIdentityClient = session.client("cognito-identity")

kwargs: CreateIdentityPoolInputRequestTypeDef = {...}
result: IdentityPoolTypeDef = client.create_identity_pool(**kwargs)
# ListIdentityPoolsPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_cognito_identity.client import CognitoIdentityClient
from mypy_boto3_cognito_identity.paginator import ListIdentityPoolsPaginator
from mypy_boto3_cognito_identity.type_defs import ListIdentityPoolsResponseTypeDef


session = Session()
client: CognitoIdentityClient = session.client("cognito-identity")

paginator: ListIdentityPoolsPaginator = client.get_paginator("list_identity_pools")
for item in paginator.paginate(...):
    item: ListIdentityPoolsResponseTypeDef
    print(item)