mypy-boto3-cognito-identity Type Stubs

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This example demonstrates how to initialize a `boto3` CognitoIdentity client with type hinting from `mypy-boto3-cognito-identity` and perform a basic operation (`get_id`). Ensure `boto3` is also installed. Type checking will catch incorrect arguments or attribute access on the `response` object.

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.

view raw JSON →