types-boto3-cognito-idp

raw JSON →
1.43.0 verified Fri May 01 auth: no python

Type annotations for boto3 CognitoIdentityProvider service. Provides static typing stubs for Amazon Cognito User Pools (IDP). Generated by mypy-boto3-builder. Version 1.43.0 requires Python >=3.9. Active development.

pip install types-boto3-cognito-idp
error Cannot find implementation or library stub for module 'mypy_boto3_cognito_idp'
cause The package is not installed or not being picked up by mypy.
fix
Run 'pip install types-boto3-cognito-idp' and ensure mypy is configured to use the stubs (e.g., 'mypy --namespace-packages ...').
error Module 'mypy_boto3_cognito_idp' has no attribute 'CognitoIdentityProviderClient'
cause Trying to import 'CognitoIdentityProviderClient' from the top-level mypy_boto3_cognito_idp package, but it is located in the 'client' submodule.
fix
Use 'from mypy_boto3_cognito_idp.client import CognitoIdentityProviderClient'.
error Name 'AdminGetUserResponseTypeDef' is not defined
cause Forgot to import the TypeDef, or imported from the wrong module (e.g., from the paginator module instead of type_defs).
fix
Add 'from mypy_boto3_cognito_idp.type_defs import AdminGetUserResponseTypeDef'.
error "Optional" is not subscriptable / "Type" is not generic
cause Using Python 3.8 with newer stubs that require 3.9+. The stubs use PEP 604 union syntax (X | None) which is only supported at runtime in Python 3.10+ and with __future__ annotations.
fix
Upgrade to Python 3.9+ and use 'from __future__ import annotations' at the top of your file, or use typing.Optional/X | None correctly.
gotcha Do NOT import 'CognitoIdentityProviderClient' directly from 'boto3'. The boto3 package does not export it; you must import from 'mypy_boto3_cognito_idp.client'. Without this, static type checkers (mypy, pyright) will not recognise the type.
fix Use 'from mypy_boto3_cognito_idp.client import CognitoIdentityProviderClient'
breaking Version 8.9.0 of mypy-boto3-builder renamed many TypeDefs by dropping redundant 'Request' suffixes (breaking change). For example, 'AdminGetUserRequestRequestTypeDef' became 'AdminGetUserRequestTypeDef'. If you pinned to an older types-boto3-cognito-idp, you may need to update your typings.
fix Rename imports: remove duplicate 'Request' in TypeDef names. For version-specific TypeDefs, check the generated stubs.
gotcha TypeDefs for paginators (e.g., ListUsersPaginator) require importing from the paginator submodule, not from type_defs. Using the wrong module will cause mypy errors.
fix Use 'from mypy_boto3_cognito_idp.paginator import ListUsersPaginator' for paginator types, and 'from mypy_boto3_cognito_idp.type_defs import ...' for service response/request types.
deprecated Python 3.8 support was removed in builder version 8.12.0. types-boto3-cognito-idp requires Python >=3.9.
fix Upgrade to Python 3.9+ or pin to an older version of the stubs (e.g., 1.34.0) if you still need 3.8.
gotcha The package name 'types-boto3-cognito-idp' is used for Boto3 v1 stubs. For aioboto3, use 'types-aioboto3-cognito-idp' instead. Mixing them leads to missing stubs.
fix Install the correct package: 'pip install types-aioboto3-cognito-idp' if you use aioboto3.

Type-annotated usage of CognitoIdentityProviderClient and AdminGetUserResponseTypeDef

import boto3
from mypy_boto3_cognito_idp.client import CognitoIdentityProviderClient
from mypy_boto3_cognito_idp.type_defs import AdminGetUserResponseTypeDef

def get_user_email(client: CognitoIdentityProviderClient, user_pool_id: str, username: str) -> str:
    response: AdminGetUserResponseTypeDef = client.admin_get_user(
        UserPoolId=user_pool_id,
        Username=username
    )
    for attr in response.get('UserAttributes', []):
        if attr['Name'] == 'email':
            return attr['Value']
    return ''

client: CognitoIdentityProviderClient = boto3.client('cognito-idp')
email = get_user_email(client, os.environ.get('USER_POOL_ID', ''), os.environ.get('USERNAME', ''))
print(email)