mypy-boto3-machinelearning

1.42.3 · active · verified Sat Apr 11

mypy-boto3-machinelearning provides type annotations for the `boto3` Machine Learning service, generated by `mypy-boto3-builder`. It enhances development experience by enabling static type checking with tools like MyPy and improving IDE autocomplete for AWS Boto3 clients, paginators, waiters, and response `TypedDict`s. The library is actively maintained with releases often mirroring `boto3` versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted `boto3` Machine Learning client and use it to list ML models. It leverages `mypy-boto3-machinelearning` for static type checking and improved IDE support. Ensure `boto3` and AWS credentials are configured in your environment.

import boto3
import os
from mypy_boto3_machinelearning.client import MachineLearningClient

def get_ml_client(region: str) -> MachineLearningClient:
    """Initializes and returns a type-hinted MachineLearning client."""
    client: MachineLearningClient = boto3.client("machinelearning", region_name=region)
    return client

def list_all_ml_models() -> None:
    """Lists all ML models using the type-hinted client."""
    region = os.environ.get('AWS_REGION', 'us-east-1')
    try:
        ml_client = get_ml_client(region)
        print(f"Listing ML models in {region}...")
        response = ml_client.describe_ml_models()
        for model in response.get('Results', []):
            print(f"  Model ID: {model.get('MLModelId')}, Name: {model.get('MLModelName')}")
        print("Successfully listed ML models.")
    except Exception as e:
        print(f"Error listing ML models: {e}")

if __name__ == "__main__":
    # Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
    # Example: export AWS_REGION='us-east-1'
    list_all_ml_models()

view raw JSON →