mypy-boto3-connect Type Stubs
mypy-boto3-connect provides comprehensive type annotations for the AWS SDK for Python (boto3) specifically for the AWS Connect service. It is automatically generated by `mypy-boto3-builder` (currently version 8.12.0) and helps users catch type-related errors at development time, improving code quality and maintainability. The current version of these stubs is 1.42.88, reflecting the boto3 version.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. This affects all generated stubs, including `mypy-boto3-connect`. Ensure your project uses Python 3.9 or higher.
- breaking All `mypy-boto3` packages, including `mypy-boto3-connect`, migrated to PEP 561 compliant packages in `mypy-boto3-builder` version 8.12.0. This might affect how some tools discover and use stubs, though `mypy` typically handles this gracefully.
- breaking In `mypy-boto3-builder` version 8.9.0, TypeDef naming conventions changed for packed method arguments and conflicting names. TypeDefs like `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`, and `Extra` postfixes moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`). While `mypy-boto3-connect` may not directly use these specific examples, similar renames could affect Connect-specific TypeDefs.
- deprecated The `sms-voice` service was deprecated and removed from `mypy-boto3-builder` in version 8.11.0. Users should migrate to `pinpoint-sms-voice` instead. This is a general `mypy-boto3` warning, not directly affecting `mypy-boto3-connect`, but important for users of the overall `mypy-boto3` ecosystem.
- gotcha You must install `boto3` alongside `mypy-boto3-connect`. `mypy-boto3-connect` only provides type stubs and does not include the runtime `boto3` library itself. Without `boto3`, your code will fail at runtime.
Install
-
pip install boto3 mypy-boto3-connect mypy
Imports
- ConnectClient
from mypy_boto3_connect import ConnectClient
- ConnectServiceResource
from mypy_boto3_connect import ConnectServiceResource
- InstanceTypeDef
from mypy_boto3_connect.type_defs import InstanceTypeDef
Quickstart
import boto3
from mypy_boto3_connect import ConnectClient
from mypy_boto3_connect.type_defs import CreateInstanceRequestRequestTypeDef, InstanceTypeDef
# Instantiate the boto3 client and cast it to the Mypy-Boto3 type for type checking
connect_client: ConnectClient = boto3.client("connect")
# Example usage with type-hinted data
# Note: This is a placeholder; actual Connect operations might require more complex setup.
# Replace with actual data relevant to your AWS Connect instance.
create_instance_request: CreateInstanceRequestRequestTypeDef = {
"ClientToken": "example-token",
"IdentityManagementType": "SAML", # Other options: 'CONNECT_MANAGED', 'EXISTING_DIRECTORY'
"InstanceAlias": "my-test-instance-alias",
"DirectoryId": "dir-xxxxxxxx", # Required if IdentityManagementType is EXISTING_DIRECTORY
"InboundCallsEnabled": True,
"OutboundCallsEnabled": True
}
# The actual call might fail without correct setup, this demonstrates type usage
try:
# This call is illustrative for type checking, it will likely fail without a real setup.
response = connect_client.create_instance(
IdentityManagementType=create_instance_request["IdentityManagementType"],
InstanceAlias=create_instance_request["InstanceAlias"],
InboundCallsEnabled=create_instance_request["InboundCallsEnabled"],
OutboundCallsEnabled=create_instance_request["OutboundCallsEnabled"]
)
# The response object will also be type-hinted if Mypy is run
instance_summary: InstanceTypeDef = response["InstanceSummary"]
print(f"Instance created with ARN: {instance_summary['Arn']}")
except Exception as e:
print(f"Could not create instance (this is expected without a valid setup): {e}")
# Example of getting an existing instance (requires an actual instance ARN)
try:
# Replace with a real instance ARN if you want to test live
instance_id = "arn:aws:connect:REGION:ACCOUNT_ID:instance/INSTANCE_ID"
# This call is illustrative for type checking
response = connect_client.describe_instance(InstanceId=instance_id)
instance_summary: InstanceTypeDef = response['Instance']['InstanceSummary']
print(f"Described instance ID: {instance_summary['Id']}")
except connect_client.exceptions.ResourceNotFoundException:
print(f"Instance {instance_id} not found.")
except Exception as e:
print(f"Could not describe instance (this is expected without a valid ARN): {e}")