Type Annotations for boto3 SSM Incidents

1.42.3 · active · verified Sat Apr 11

mypy-boto3-ssm-incidents provides official type annotations (stubs) for the boto3 AWS SSM Incidents service client. It allows users to leverage static type checking with tools like MyPy, improving code quality and catching errors early. This library is automatically generated by the `mypy-boto3-builder` and its version typically aligns with the corresponding `boto3` service version. The current version is 1.42.3, reflecting the boto3 API version, and updates frequently alongside new boto3 releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-ssm-incidents` for type-hinting a boto3 SSM Incidents client. It shows the use of `TYPE_CHECKING` to guard stub imports and provides an example API call with inferred types.

import os
import boto3
from typing import TYPE_CHECKING

# These imports are only for type checking purposes.
# They are ignored at runtime if TYPE_CHECKING is False.
if TYPE_CHECKING:
    from mypy_boto3_ssm_incidents import SSMIncidentsClient
    from mypy_boto3_ssm_incidents.type_defs import GetIncidentRecordOutputTypeDef

# Initialize the boto3 client at runtime
# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
client: 'SSMIncidentsClient' = boto3.client(
    "ssm-incidents",
    region_name=os.environ.get("AWS_REGION", "us-east-1")
)

# Example API call with type hints
try:
    # Use a dummy ARN for demonstration; replace with a valid one if you have it
    incident_arn = "arn:aws:ssm-incidents::123456789012:incident-record/example-incident"
    
    response: 'GetIncidentRecordOutputTypeDef' = client.get_incident_record(
        incidentRecordArn=incident_arn
    )
    print(f"Incident found: {response['incidentRecord']['title']}")
except client.exceptions.ResourceNotFoundException:
    print(f"Incident record '{incident_arn}' not found (as expected for example ARN).")
except Exception as e:
    print(f"An error occurred: {e}")

print("Type checking setup successful!")

view raw JSON →