mypy-boto3-connect Type Stubs

1.42.88 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to import `ConnectClient` and use it to type-hint a `boto3` AWS Connect client. It shows an example of using type-hinted request parameters for `create_instance` and retrieving `InstanceTypeDef` from the response, leveraging the static type checking provided by `mypy-boto3-connect`.

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}")

view raw JSON →