Type annotations for aiobotocore CognitoIdentityProvider
This package provides PEP 561-compatible type annotations for the `aiobotocore` library's CognitoIdentityProvider service client. It is generated by `mypy-boto3-builder` and ensures type safety for `aiobotocore` calls, enhancing developer experience with static analysis tools like MyPy. The current version is 3.4.0, aligning with a specific `aiobotocore` service version, and it releases frequently to match upstream AWS API changes and builder updates.
Common errors
-
ModuleNotFoundError: No module named 'types_aiobotocore_cognito_idp'
cause The `types-aiobotocore-cognito-idp` package has not been installed in your environment.fixRun `pip install types-aiobotocore-cognito-idp`. -
error: Module 'aiobotocore.client' has no attribute 'CognitoIdentityProviderClient' [attr-defined] or similar type errors for aiobotocore methods.
cause The `aiobotocore` library is installed, but the corresponding type stub package `types-aiobotocore-cognito-idp` is either missing or not being picked up by your type checker (e.g., MyPy).fixEnsure `types-aiobotocore-cognito-idp` is installed and your type checker is configured correctly (e.g., for MyPy, ensure it's run without `--ignore-missing-imports` for `aiobotocore` and that the stubs are in `sys.path`). Make sure `aiobotocore` itself is installed. -
error: Name "CognitoIdentityProviderClient" is not defined [name-not-defined] (when attempting `client = CognitoIdentityProviderClient()`)
cause You are trying to instantiate `CognitoIdentityProviderClient` directly. This is a type alias/interface for type checking, not a concrete class that can be instantiated at runtime.fixInstead of `CognitoIdentityProviderClient()`, create the client using `aiobotocore.get_session().create_client('cognito-idp')`. The `CognitoIdentityProviderClient` import is used only for type hints, e.g., `client: CognitoIdentityProviderClient = ...`.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generated `types-aiobotocore-cognito-idp` 3.4.0), Python 3.8 is no longer supported for any generated packages.
- gotcha This package provides *only* type annotations (stubs) for `aiobotocore`. It does not contain any runtime code for interacting with AWS. You must install `aiobotocore` separately for your application to function.
Install
-
pip install types-aiobotocore-cognito-idp
Imports
- CognitoIdentityProviderClient
from types_aiobotocore_cognito_idp.client import CognitoIdentityProviderClient
- ListUsersResponseTypeDef
from types_aiobotocore_cognito_idp.type_defs import ListUsersResponseTypeDef
- ListUsersPaginator
from types_aiobotocore_cognito_idp.paginator import ListUsersPaginator
Quickstart
import asyncio
import os
import aiobotocore
from types_aiobotocore_cognito_idp.client import CognitoIdentityProviderClient
from types_aiobotocore_cognito_idp.type_defs import ListUsersResponseTypeDef
async def main():
# Ensure AWS credentials are set up (e.g., via environment variables, ~/.aws/credentials)
# This example assumes you have valid credentials for Cognito User Pools.
# Using aiobotocore.get_session() is the recommended way for aiobotocore
session = aiobotocore.get_session()
async with session.create_client(
"cognito-idp",
region_name=os.environ.get("AWS_REGION", "us-east-1"),
aws_access_key_id=os.environ.get("AWS_ACCESS_KEY_ID", ""), # Provide actual credentials or rely on env/config
aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY", ""), # Provide actual credentials or rely on env/config
) as client:
# The client object will be correctly typed as CognitoIdentityProviderClient
# by type checkers like MyPy due to the installed stubs.
typed_client: CognitoIdentityProviderClient = client
user_pool_id = os.environ.get("COGNITO_USER_POOL_ID", "") # Replace with your User Pool ID
if not user_pool_id:
print("Error: COGNITO_USER_POOL_ID environment variable not set.")
return
try:
response: ListUsersResponseTypeDef = await typed_client.list_users(
UserPoolId=user_pool_id,
Limit=2
)
print(f"Successfully listed users in User Pool '{user_pool_id}':")
for user in response.get("Users", []):
print(f" - Username: {user.get('Username')}, Status: {user.get('UserStatus')}")
if "PaginationToken" in response:
print(f" (Next token: {response['PaginationToken']})")
except Exception as e:
print(f"Error listing users: {e}")
print("Ensure COGNITO_USER_POOL_ID and AWS credentials are correctly set and have permissions.")
if __name__ == "__main__":
# To run this example, set environment variables:
# export AWS_REGION="your-aws-region"
# export AWS_ACCESS_KEY_ID="your-access-key"
# export AWS_SECRET_ACCESS_KEY="your-secret-key"
# export COGNITO_USER_POOL_ID="your-cognito-user-pool-id"
asyncio.run(main())