Skip to content

Examples#

Index > CognitoIdentityProvider > Examples

Auto-generated documentation for CognitoIdentityProvider type annotations stubs module mypy-boto3-cognito-idp.

Client#

Implicit type annotations#

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

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

# CognitoIdentityProviderClient usage example

from boto3.session import Session


session = Session()

client = session.client("cognito-idp")  # (1)
result = client.admin_add_user_to_group()  # (2)
  1. client: CognitoIdentityProviderClient
  2. result: EmptyResponseMetadataTypeDef
# AdminListGroupsForUserPaginator usage example

from boto3.session import Session


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

paginator = client.get_paginator("admin_list_groups_for_user")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: CognitoIdentityProviderClient
  2. paginator: AdminListGroupsForUserPaginator
  3. item: AdminListGroupsForUserResponseTypeDef

Explicit type annotations#

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

# CognitoIdentityProviderClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_cognito_idp.client import CognitoIdentityProviderClient
from mypy_boto3_cognito_idp.type_defs import EmptyResponseMetadataTypeDef
from mypy_boto3_cognito_idp.type_defs import AdminAddUserToGroupRequestRequestTypeDef


session = Session()

client: CognitoIdentityProviderClient = session.client("cognito-idp")

kwargs: AdminAddUserToGroupRequestRequestTypeDef = {...}
result: EmptyResponseMetadataTypeDef = client.admin_add_user_to_group(**kwargs)
# AdminListGroupsForUserPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_cognito_idp.client import CognitoIdentityProviderClient
from mypy_boto3_cognito_idp.paginator import AdminListGroupsForUserPaginator
from mypy_boto3_cognito_idp.type_defs import AdminListGroupsForUserResponseTypeDef


session = Session()
client: CognitoIdentityProviderClient = session.client("cognito-idp")

paginator: AdminListGroupsForUserPaginator = client.get_paginator("admin_list_groups_for_user")
for item in paginator.paginate(...):
    item: AdminListGroupsForUserResponseTypeDef
    print(item)