Type Annotations for boto3 EMR Containers

1.42.3 · active · verified Sat Apr 11

mypy-boto3-emr-containers provides static type annotations (stubs) for the boto3 EMR Containers service, enhancing development with type-checking capabilities. It ensures type safety when using boto3 clients, resources, and collections for EMR Containers, preventing common runtime errors. The library is automatically generated by mypy-boto3-builder and typically releases new versions in sync with boto3 and botocore updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a type-hinted EMR Containers client and use it to list virtual clusters. The `EMRContainersClient` type ensures that method calls and return values are correctly type-checked by tools like mypy, catching potential issues at development time rather than runtime. Remember to have `boto3` installed alongside the stubs.

import boto3
from mypy_boto3_emr_containers import EMRContainersClient
from mypy_boto3_emr_containers.type_defs import ListVirtualClustersOutputTypeDef

def get_emr_containers_client() -> EMRContainersClient:
    """Returns a type-hinted EMR Containers client."""
    # Ensure boto3 is installed: pip install boto3 mypy-boto3-emr-containers
    client: EMRContainersClient = boto3.client("emr-containers")
    return client

def list_virtual_clusters() -> None:
    """Lists EMR Containers virtual clusters with type checking."""
    client = get_emr_containers_client()
    try:
        response: ListVirtualClustersOutputTypeDef = client.list_virtual_clusters()
        print("Successfully listed virtual clusters:")
        for cluster in response.get("virtualClusters", []):
            name = cluster.get("name", "N/A")
            cluster_id = cluster.get("id", "N/A")
            status = cluster.get("status", {}).get("state", "UNKNOWN")
            print(f"  - Name: {name}, ID: {cluster_id}, Status: {status}")
        if not response.get("virtualClusters"):
            print("  No virtual clusters found.")
    except Exception as e:
        print(f"Error listing virtual clusters: {e}")

if __name__ == "__main__":
    list_virtual_clusters()

view raw JSON →