mypy-boto3-cognito-identity Type Stubs
This library provides PEP 561 compliant type annotations (stubs) for the `boto3` client for AWS CognitoIdentity service. It enhances type checking for `boto3` calls, improving code reliability and developer experience. Maintained by the `mypy-boto3-builder` project, it releases frequently, often in sync with new `boto3` service definitions or `mypy-boto3-builder` updates.
Warnings
- breaking Python 3.8 is no longer supported. Packages built with `mypy-boto3-builder` 8.12.0+ (including this version) require Python 3.9 or newer.
- breaking Migration to PEP 561 packaging (namespace packages). While generally transparent, this change might require updating your `mypy` version or refreshing your virtual environment if you encounter issues with stub discovery.
- gotcha This package provides *only* type stubs. You must separately install the `boto3` library for actual runtime functionality. `mypy-boto3-cognito-identity` does not replace `boto3`.
- breaking TypeDef naming conventions changed for packed method arguments, potentially breaking existing type hints if custom TypeDefs were manually defined or referenced. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`.
- gotcha Service support within the `mypy-boto3` ecosystem can change. Services might be deprecated, renamed (e.g., `sms-voice` to `pinpoint-sms-voice`), or excluded from builds, potentially breaking imports for other `mypy-boto3-*` packages.
Install
-
pip install mypy-boto3-cognito-identity
Imports
- CognitoIdentityClient
from mypy_boto3_cognito_identity.client import CognitoIdentityClient
- ListIdentitiesPaginator
from mypy_boto3_cognito_identity.paginator import ListIdentitiesPaginator
- GetIdResponseTypeDef
from mypy_boto3_cognito_identity.type_defs import GetIdResponseTypeDef
Quickstart
import boto3
import os
from mypy_boto3_cognito_identity.client import CognitoIdentityClient
from mypy_boto3_cognito_identity.type_defs import GetIdResponseTypeDef
# Instantiate a boto3 client for CognitoIdentity, type-hinted by the stubs
# In a real application, credentials would be managed via IAM roles or environment variables.
client: CognitoIdentityClient = boto3.client(
"cognito-identity",
region_name="us-east-1", # Replace with your AWS region
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', '')
)
# Example: Get an identity ID (replace with actual AccountId and IdentityPoolId)
# Note: This operation creates an identity if it doesn't exist for the given pool.
try:
response: GetIdResponseTypeDef = client.get_id(
AccountId="123456789012", # Replace with a valid AWS Account ID
IdentityPoolId="us-east-1:abcdefgh-abcd-abcd-abcd-abcdefghijkl" # Replace with a valid Identity Pool ID
)
identity_id = response.get('IdentityId')
print(f"Successfully retrieved Identity ID: {identity_id}")
except Exception as e:
print(f"An error occurred: {e}")
# Mypy will now correctly validate argument types and response structure.