mypy-boto3-cognito-sync Type Stubs for boto3 CognitoSync
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
- breaking Python 3.8 support was removed for all `mypy-boto3` packages (including this one) in `mypy-boto3-builder` version 8.12.0. Projects must use Python 3.9 or newer.
- breaking All `mypy-boto3` packages migrated to PEP 561, changing how type checkers discover packages. Ensure your `mypy` configuration (if any) is compatible with standard PEP 561 stub discovery.
- breaking TypedDict argument names for packed methods were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were reordered in `mypy-boto3-builder 8.9.0`. This can break explicit `TypeDef` imports or usage if not updated.
- gotcha This package provides only type stubs for `boto3-stubs`. You must install the actual `boto3` library separately for your application to run. `mypy-boto3-cognito-sync` is a development dependency, not a runtime dependency.
- gotcha When installing `boto3-stubs` with service-specific extras (e.g., `boto3-stubs[cognito-sync]`), the version of the individual `mypy-boto3-*` sub-package might not be strictly locked to the specified `boto3-stubs` version. This can lead to unexpected type-checking errors if the installed sub-package is significantly newer than anticipated.
- gotcha Using `Literal` type overloads can cause slow performance and high CPU usage in PyCharm (issue PY-40997). For PyCharm users, `boto3-stubs-lite` is recommended as an alternative for better IDE responsiveness.
- gotcha When using `Pylint` with `TYPE_CHECKING` blocks for conditional stub imports, `Pylint` may complain about undefined variables. This requires setting the conditionally imported types to `object` in the non-`TYPE_CHECKING` branch.
Install
-
pip install mypy-boto3-cognito-sync -
pip install 'boto3-stubs[cognito-sync]'
Imports
- CognitoSyncClient
from mypy_boto3_cognito_sync import CognitoSyncClient
- BulkPublishStatusType
from mypy_boto3_cognito_sync.literals import BulkPublishStatusType
- BulkPublishRequestTypeDef
from mypy_boto3_cognito_sync.type_defs import BulkPublishRequestTypeDef
Quickstart
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}")