mypy-boto3-cognito-sync Type Stubs for boto3 CognitoSync

1.42.3 · active · verified Sat Apr 11

mypy-boto3-cognito-sync provides type annotations (stubs) for the boto3 AWS SDK, specifically for the Cognito Sync service. It is part of the larger mypy-boto3 project, which automatically generates these stubs in sync with boto3 releases to ensure up-to-date type checking for AWS services. The current version is 1.42.3, generated with mypy-boto3-builder 8.12.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `CognitoSyncClient` type annotation with a boto3 Cognito Sync client. The `TYPE_CHECKING` guard is a best practice to avoid importing the stubs at runtime, making them purely a development dependency. The example shows a typical `list_datasets` operation, which benefits from type hints on client methods and response structures.

from typing import TYPE_CHECKING
import boto3

if TYPE_CHECKING:
    from mypy_boto3_cognito_sync import CognitoSyncClient
    from mypy_boto3_cognito_sync.type_defs import DatasetTypeDef

# Initialize a boto3 session and client
session = boto3.session.Session()
client: "CognitoSyncClient" = session.client("cognito-sync")

# Example: List Identity Pools (Cognito Sync operations often tie to Identity Pools)
# Note: Cognito Sync operations are typically tied to specific identities or datasets.
# This example is illustrative for client type-checking.
try:
    # Placeholder for actual Cognito Sync operation, as ListIdentityPools is CognitoIdentity
    # A more realistic CognitoSync operation would be something like list_records
    # For this example, we'll simulate a call that uses the client.
    # In a real scenario, you'd provide IdentityPoolId, IdentityId, DatasetName, etc.
    # For demonstration, we'll use a dummy call that the client can execute.
    # (Note: CognitoSync doesn't have a simple 'list all' like many services)
    
    # A common operation is to list datasets for an identity.
    identity_pool_id = os.environ.get('COGNITO_IDENTITY_POOL_ID', 'us-east-1:xxxx-xxxx-xxxx') # Dummy ID
    identity_id = os.environ.get('COGNITO_IDENTITY_ID', 'us-east-1:xxxx-xxxx-xxxx') # Dummy ID
    
    response = client.list_datasets(
        IdentityPoolId=identity_pool_id,
        IdentityId=identity_id
    )
    
    print("Datasets:")
    for dataset in response.get("Datasets", []):
        # dataset is type-checked as DatasetTypeDef
        dataset_typed: "DatasetTypeDef" = dataset
        print(f"  Dataset Name: {dataset_typed['DatasetName']}, Num Records: {dataset_typed['NumRecords']}")

except client.exceptions.ResourceNotFoundException:
    print(f"Identity Pool or Identity not found for ID: {identity_pool_id}, {identity_id}")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →