mypy-boto3-directconnect Type Annotations

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-directconnect` to add type hints to your `boto3` Direct Connect client. It shows how to import the `DirectConnectClient` type and apply it to a `boto3.client()` call, enabling `mypy` to validate your service interactions. It also includes an example of importing and using a specific `TypeDef` for enhanced type safety when accessing response data.

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()

view raw JSON →