mypy-boto3-directconnect Type Annotations
mypy-boto3-directconnect provides type annotations for the `boto3` AWS Direct Connect service client. It ensures type-safe usage of `boto3` calls related to Direct Connect in Python projects, catching potential errors during static analysis with `mypy`. The current version is `1.42.3`, and it's released in conjunction with `boto3` updates and `mypy-boto3-builder` enhancements.
Warnings
- breaking Python 3.8 is no longer supported. `mypy-boto3-builder` version 8.12.0 and subsequent packages (including `mypy-boto3-directconnect`) require Python 3.9 or higher.
- breaking The `mypy-boto3-builder` migrated to PEP 561 packages, which may affect how `mypy` discovers and uses the type stubs, especially for custom configurations.
- gotcha Version mismatch between `boto3` and `mypy-boto3-*` stubs can lead to incorrect type checking or missing types. These packages are generated for specific `boto3` versions.
- gotcha Service-specific TypedDict names were shortened or adjusted in `mypy-boto3-builder` 8.9.0 to avoid conflicts or reduce verbosity (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`).
Install
-
pip install mypy-boto3-directconnect boto3 mypy
Imports
- DirectConnectClient
from mypy_boto3_directconnect import DirectConnectClient
- DescribeConnectionsPaginator
from mypy_boto3_directconnect.paginator import DescribeConnectionsPaginator
- ConnectionStatusType
from mypy_boto3_directconnect.type_defs import ConnectionStatusType
Quickstart
import boto3
from mypy_boto3_directconnect import DirectConnectClient
from mypy_boto3_directconnect.type_defs import ConnectionTypePairTypeDef
def list_direct_connect_connections() -> None:
# Initialize the boto3 client with type hints
client: DirectConnectClient = boto3.client('directconnect')
print("Listing Direct Connect connections...")
try:
response = client.describe_connections()
for connection in response.get('connections', []):
print(f" Connection ID: {connection['connectionId']}")
print(f" Connection Name: {connection['connectionName']}")
print(f" Connection State: {connection['connectionState']}")
if 'connectionType' in connection:
# Example of using a TypedDict for a specific field
type_info: ConnectionTypePairTypeDef = {
'connectionType': connection['connectionType']
}
print(f" Connection Type: {type_info['connectionType']}")
except Exception as e:
print(f"Error listing connections: {e}")
if __name__ == '__main__':
list_direct_connect_connections()