mypy-boto3-health type annotations
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
- breaking Python 3.8 support has been removed across all `mypy-boto3` packages, and all packages have migrated to PEP 561. This may require upgrading your Python environment and reviewing how stubs are resolved by your type checker.
- breaking TypeDef naming conventions changed for packed method arguments and conflict resolution. This primarily impacts users relying on specific TypeDef names for complex input/output structures within the stubs.
- gotcha This package provides *only* type annotations. You must install `boto3` separately for your application to actually interact with AWS services at runtime.
- gotcha AWS service names and their corresponding `mypy-boto3` package names can sometimes change or be deprecated (e.g., `sms-voice` replaced by `pinpoint-sms-voice`). Ensure you are using the correct and most up-to-date service name.
Install
-
pip install mypy-boto3-health
Imports
- HealthClient
from mypy_boto3_health.client import HealthClient
- DescribeEventsResponseTypeDef
from mypy_boto3_health.type_defs import DescribeEventsResponseTypeDef
Quickstart
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}")