mypy-boto3-sagemaker-a2i-runtime type annotations

1.42.3 · active · verified Sat Apr 11

This library provides type annotations (stubs) for the `boto3` client and resources related to the AWS SageMaker Augmented AI Runtime (A2I) service. It allows static type checkers like MyPy to validate code using `boto3` for this specific AWS service, catching potential errors before runtime. The current version is `1.42.3`, and releases are frequent, typically in sync with `boto3` updates and `mypy-boto3-builder` improvements.

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize a type-hinted `boto3` client for the Sagemaker A2I Runtime service and use it to list flow definitions. MyPy will provide strong type-checking for the client methods and the structure of the API responses, leveraging the installed stubs.

import boto3
from mypy_boto3_sagemaker_a2i_runtime.client import AugmentedAIRuntimeClient
from mypy_boto3_sagemaker_a2i_runtime.type_defs import HumanLoopSummaryTypeDef
import os


def get_a2i_client() -> AugmentedAIRuntimeClient:
    """Initializes and returns a typed Sagemaker A2I Runtime client."""
    # Ensure AWS credentials are configured (e.g., via environment variables, ~/.aws/credentials)
    # For local development, you might use 'aws configure'
    # For production, consider IAM roles.
    client: AugmentedAIRuntimeClient = boto3.client(
        "sagemaker-a2i-runtime",
        region_name=os.environ.get("AWS_REGION", "us-east-1")
    )
    return client


def list_a2i_flow_definitions():
    """Lists A2I flow definitions using the typed client."""
    client = get_a2i_client()
    try:
        # MyPy will now correctly type-check the client's methods and response structure
        response = client.list_flow_definitions(MaxResults=10)
        flow_definitions: list[HumanLoopSummaryTypeDef] = response["HumanLoopSummaries"]

        print(f"Found {len(flow_definitions)} A2I Flow Definitions:")
        for fd in flow_definitions:
            print(f"- Name: {fd['FlowDefinitionName']}, Status: {fd['FlowDefinitionStatus']}")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    list_a2i_flow_definitions()

view raw JSON →