mypy-boto3-application-insights Type Stubs
mypy-boto3-application-insights provides comprehensive type annotations for the `boto3` client interacting with the AWS Application Insights service. It ensures that your Python code leveraging `boto3` for Application Insights interactions is type-checked by `mypy`, catching potential errors at development time. This package is part of the `mypy-boto3-builder` ecosystem, which generates stubs for all `boto3` services, and is frequently updated to align with `boto3` and `botocore` releases. The current version is 1.42.3.
Warnings
- breaking Python 3.8 is no longer supported. Packages generated with `mypy-boto3-builder` version 8.12.0 and later, including `mypy-boto3-application-insights` 1.42.3+, require Python 3.9 or higher.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. This could affect existing type hint usages for service-specific request/response types (e.g., `CreateDistributionRequestRequestTypeDef` was shortened to `CreateDistributionRequestTypeDef`).
- gotcha This package provides type stubs only. You must also install `boto3` (or `aioboto3`) separately for runtime functionality, as the stub package does not include it as a runtime dependency.
- gotcha For optimal runtime performance and to avoid loading stubs in production, it is recommended to guard `mypy-boto3` imports with `if typing.TYPE_CHECKING:`.
Install
-
pip install boto3 mypy-boto3-application-insights
Imports
- ApplicationInsightsClient
from mypy_boto3_application_insights import ApplicationInsightsClient
- ApplicationInsightsClient
from mypy_boto3_application_insights.client import ApplicationInsightsClient
- ListApplicationsOutputTypeDef
from mypy_boto3_application_insights.type_defs import ListApplicationsOutputTypeDef
Quickstart
import boto3
import os
from typing import TYPE_CHECKING
# Ensure boto3 and mypy-boto3-application-insights are installed:
# pip install boto3 mypy-boto3-application-insights
if TYPE_CHECKING:
# These imports are only for type checking and will not be executed at runtime.
from mypy_boto3_application_insights import ApplicationInsightsClient
from mypy_boto3_application_insights.type_defs import (
ListApplicationsOutputTypeDef,
ApplicationTypeDef,
)
# Instantiate a boto3 client.
# mypy-boto3 provides the type hints for this client.
client: "ApplicationInsightsClient" = boto3.client(
"application-insights",
region_name=os.environ.get("AWS_REGION", "us-east-1"),
# The following are placeholder values for demonstration; use actual credentials.
aws_access_key_id=os.environ.get("AWS_ACCESS_KEY_ID", "MOCK_KEY"),
aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY", "MOCK_SECRET"),
aws_session_token=os.environ.get("AWS_SESSION_TOKEN", "MOCK_TOKEN")
)
print(f"Boto3 client instantiated (runtime type: {type(client)}).")
# Example usage with type-checked response and error handling
try:
# The response variable will be type-hinted as ListApplicationsOutputTypeDef
response: "ListApplicationsOutputTypeDef" = client.list_applications()
# Access type-hinted data from the response
applications: list["ApplicationTypeDef"] = response.get("ApplicationInfoList", [])
print(f"Found {len(applications)} Application Insights applications.")
if applications:
print(f"First application name: {applications[0]['ApplicationName']}")
except client.exceptions.ResourceNotFoundException:
print("No Application Insights applications found or insufficient permissions.")
except Exception as e:
print(f"An unexpected error occurred: {e}")