Type annotations for boto3 IoTEvents

1.42.3 · active · verified Sat Apr 11

mypy-boto3-iotevents provides type annotations for the boto3 IoTEvents service (version 1.42.3), generated by mypy-boto3-builder 8.12.0. It enhances developer experience by enabling static type checking with tools like MyPy, Pyright, VSCode, and PyCharm, improving code quality, readability, and allowing for early detection of potential runtime errors in AWS SDK for Python (boto3) interactions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted boto3 IoTEvents client and make a simple API call. It shows how to import the specific client type and a response type definition for improved static analysis and IDE autocomplete. Ensure `boto3` is installed alongside `mypy-boto3-iotevents`.

import boto3
from mypy_boto3_iotevents import IoTEventsClient
from mypy_boto3_iotevents.type_defs import ListDetectorModelsResponseTypeDef
import os

def get_iotevents_client() -> IoTEventsClient:
    """Initializes and returns a type-hinted IoTEvents client."""
    # AWS credentials are typically configured via environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION)
    # or AWS CLI configuration.
    # Using os.environ.get for example purposes; in production, boto3 handles credential resolution.
    client: IoTEventsClient = boto3.client(
        "iotevents",
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )
    return client

if __name__ == "__main__":
    try:
        iotevents_client = get_iotevents_client()
        print("Successfully initialized IoTEvents client.")

        # Example: List detector models with type-hinted response
        response: ListDetectorModelsResponseTypeDef = iotevents_client.list_detector_models()
        print(f"Found {len(response.get('detectorModelSummaries', []))} detector models.")

    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →