mypy-boto3-codeconnections

1.42.3 · active · verified Sat Apr 11

mypy-boto3-codeconnections provides type annotations for the `boto3` AWS CodeConnections service. It enables static type checking for `boto3` interactions, improving code readability, auto-completion in IDEs, and allowing early error detection for AWS API calls. This package is generated by `mypy-boto3-builder` version 8.12.0 and is frequently updated, typically in sync with `boto3` releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a type-hinted `CodeConnectionsClient` and interact with it. It uses `TYPE_CHECKING` for conditional import and `cast` to inform the type checker, ensuring that your IDE provides correct auto-completion and static analysis while `boto3` handles the runtime. A dummy response is used to make the example runnable without actual AWS credentials.

import boto3
from typing import TYPE_CHECKING, cast
import os

if TYPE_CHECKING:
    from mypy_boto3_codeconnections.client import CodeConnectionsClient
    from mypy_boto3_codeconnections.type_defs import ListConnectionsOutputTypeDef

def get_codeconnections_client() -> "CodeConnectionsClient":
    """
    Returns a type-hinted boto3 CodeConnections client.
    """
    # In a real application, region_name might come from environment or config.
    client = boto3.client("codeconnections", region_name=os.environ.get("AWS_REGION_NAME", "us-east-1"))
    return cast("CodeConnectionsClient", client)

def list_all_connections():
    """
    Lists all CodeConnections connections with type hints.
    """
    client = get_codeconnections_client()
    
    # In a live environment, this would be an actual API call:
    # response: ListConnectionsOutputTypeDef = client.list_connections()

    # For a runnable example, we use a dummy response matching the expected type.
    response: "ListConnectionsOutputTypeDef" = {
        "Connections": [
            {
                "ConnectionArn": "arn:aws:codeconnections:us-east-1:123456789012:connection/a1b2c3d4",
                "ConnectionName": "my-github-connection",
                "ProviderType": "GitHub",
                "OwnerAccountId": "123456789012",
                "ConnectionStatus": "AVAILABLE"
            }
        ],
        "NextToken": None
    }
    
    print("CodeConnections:")
    for connection in response.get("Connections", []):
        print(f"  - Name: {connection['ConnectionName']}, ARN: {connection['ConnectionArn']}")
    
    return response

if __name__ == '__main__':
    # Set dummy environment variables for the example to run locally without actual AWS credentials.
    # In a real scenario, boto3 would automatically pick these up or use IAM roles.
    os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY')
    os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET')
    os.environ['AWS_REGION_NAME'] = os.environ.get('AWS_REGION_NAME', 'us-east-1')

    list_all_connections()

view raw JSON →