mypy-boto3-cognito-idp
mypy-boto3-cognito-idp provides comprehensive type annotations for the `boto3` library's Cognito Identity Provider service. It enables static type checking with tools like mypy and pyright, offering enhanced auto-completion and early error detection in IDEs for `boto3` calls related to Cognito IDP. The library, currently at version 1.42.59, is auto-generated by `mypy-boto3-builder` and frequently updated to synchronize with `boto3` releases, ensuring up-to-date and accurate type definitions.
Warnings
- breaking Python 3.8 support was removed in `mypy-boto3-builder` version 8.12.0 and subsequent generated packages. Users on Python 3.8 will encounter issues and must upgrade to Python 3.9 or newer.
- breaking Migration to PEP 561 compliant packages in `mypy-boto3-builder` 8.12.0 might affect how type checkers discover stubs. While typically seamless, ensure your type checker configuration is up-to-date.
- gotcha The `mypy-boto3-cognito-idp` package provides *only* type stubs. The actual `boto3` library must be installed separately in your environment for the code to run.
- gotcha Mismatching versions between your installed `boto3` library and `mypy-boto3-cognito-idp` can lead to inaccurate or missing type hints. `mypy-boto3` packages are versioned to match corresponding `boto3` versions.
- breaking In `mypy-boto3-builder` 8.9.0, there were breaking changes to TypeDef naming conventions, including using shorter names for packed method arguments (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and moving the `Extra` postfix for conflicting TypeDefs.
- gotcha PyCharm users may experience slow performance or high CPU usage due to how PyCharm handles Literal overloads. `boto3-stubs-lite` or disabling PyCharm's type checker in favor of `mypy` or `pyright` is recommended.
Install
-
pip install mypy-boto3-cognito-idp -
pip install 'boto3-stubs[cognito-idp]'
Imports
- CognitoIdentityProviderClient
from mypy_boto3_cognito_idp.client import CognitoIdentityProviderClient
Quickstart
import boto3
from boto3.session import Session
from mypy_boto3_cognito_idp.client import CognitoIdentityProviderClient
def get_cognito_idp_client(region_name: str = 'us-east-1') -> CognitoIdentityProviderClient:
"""Returns a type-hinted CognitoIdentityProvider client."""
# Actual boto3 client (runtime)
session: Session = boto3.session.Session()
client: CognitoIdentityProviderClient = session.client(
"cognito-idp",
region_name=region_name,
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', '')
)
return client
# Example usage
if __name__ == "__main__":
import os
os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY')
os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_KEY')
cognito_client = get_cognito_idp_client()
# You now have auto-completion and type checking for cognito_client methods
# For example, cognito_client.list_user_pools() will show correct types.
# response = cognito_client.list_user_pools(MaxResults=10)
print(f"Client type: {type(cognito_client)}")
# This client object now benefits from mypy-boto3 type hints.