mypy-boto3-health type annotations

1.42.59 · active · verified Sat Apr 11

mypy-boto3-health provides type annotations (stubs) for the AWS Boto3 Health service. It enables static type checking with tools like MyPy, improving code quality and catching potential errors for applications interacting with AWS Health. The library is actively maintained and releases frequently, often in sync with new `boto3` versions or `mypy-boto3-builder` updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a typed Boto3 Health client and use its methods with full type hint support. It includes an example of calling `describe_events` and accessing the typed response.

import boto3
from mypy_boto3_health.client import HealthClient
from mypy_boto3_health.type_defs import DescribeEventsResponseTypeDef
import os

# Instantiate a typed Boto3 Health client
# Ensure AWS_REGION is set in your environment or passed explicitly
region = os.environ.get("AWS_REGION", "us-east-1")
health_client: HealthClient = boto3.client("health", region_name=region)

print(f"Fetching health events in {region}...")

try:
    # Use a typed method and receive a typed response
    response: DescribeEventsResponseTypeDef = health_client.describe_events(
        filter={
            "eventStatusCodes": ["open"],
        }
    )
    events = response.get("events", [])
    if events:
        print(f"Found {len(events)} open health events:")
        for event in events:
            print(f"  Event ARN: {event['eventArn']}, Type: {event['eventTypeCategory']}")
    else:
        print("No open health events found.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →