Type Annotations for boto3 SSM Incidents
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
- breaking Python 3.8 is no longer supported by `mypy-boto3-builder` and consequently by `mypy-boto3` packages generated with it.
- breaking `mypy-boto3` packages migrated to PEP 561. This change affects how MyPy locates and uses the stubs.
- gotcha Type stub imports (`from mypy_boto3_ssm_incidents import ...`) should always be wrapped in an `if TYPE_CHECKING:` block.
- gotcha `mypy-boto3-ssm-incidents` provides *only* type annotations. The actual `boto3` library must be installed separately for your code to run.
- breaking TypeDef naming conventions changed in earlier `mypy-boto3-builder` versions, impacting how some specific TypeDefs are named (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`).
Install
-
pip install mypy-boto3-ssm-incidents boto3
Imports
- SSMIncidentsClient
from mypy_boto3_ssm_incidents import SSMIncidentsClient
- GetIncidentRecordOutputTypeDef
from mypy_boto3_ssm_incidents.type_defs import GetIncidentRecordOutputTypeDef
Quickstart
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!")