Type Annotations for boto3 IoTAnalytics

1.42.3 · active · verified Sat Apr 11

mypy-boto3-iotanalytics provides type annotations for the `boto3` AWS SDK's IoTAnalytics service, enabling static type checking with tools like `mypy` and enhancing IDE support. It is part of the `mypy-boto3` family of stub packages, automatically generated by `mypy-boto3-builder`, and its versioning typically follows the `boto3` release cadence. The current version is 1.42.3.

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize an `IoTAnalyticsClient` with type hints and perform a simple operation like listing channels. Ensure `boto3` is installed and AWS credentials are configured in your environment.

import os
import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_iotanalytics import IoTAnalyticsClient
    from mypy_boto3_iotanalytics.type_defs import ListChannelsResponseTypeDef

def list_iotanalytics_channels() -> "ListChannelsResponseTypeDef":
    """
    Lists IoTAnalytics channels with type hints.
    """
    # Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
    # The 'region_name' can also be passed here, e.g., region_name=os.environ.get('AWS_REGION', 'us-east-1')
    client: "IoTAnalyticsClient" = boto3.client(
        "iotanalytics", 
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )
    
    print("Listing IoTAnalytics channels...")
    response: "ListChannelsResponseTypeDef" = client.list_channels()
    
    for channel in response.get("channelSummaries", []):
        print(f"  Channel Name: {channel.get('channelName')}")
        print(f"  Creation Time: {channel.get('creationTime')}")
    
    return response

if __name__ == "__main__":
    try:
        # Example assumes AWS credentials are set up in the environment
        # e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
        list_iotanalytics_channels()
    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →