mypy-boto3-application-insights Type Stubs

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to set up and use `mypy-boto3-application-insights` to get type hints for your `boto3` Application Insights client. It includes conditional imports (`if TYPE_CHECKING:`) for optimal runtime performance and illustrates basic client instantiation and interaction with type-checked responses. Remember to have `boto3` installed for runtime execution.

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}")

view raw JSON →