Type annotations for boto3 IoTEvents
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
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 should update their Python version or use an older version of `mypy-boto3-iotevents` if available.
- breaking In `mypy-boto3-builder` version 8.9.0, some TypeDef names were shortened or reordered (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). While not specific to `iotevents`, this general change in naming conventions for packed method arguments can break existing type hints if specific TypeDefs are imported.
- gotcha For optimal type checking and IDE support (especially in VSCode and PyCharm), it is recommended to explicitly type annotate `boto3.client()` and `boto3.session.client()` calls with the imported client type (e.g., `client: IoTEventsClient = boto3.client("iotevents")`).
- gotcha This package only provides type annotations. You must install the `boto3` library separately for your code to function at runtime.
- gotcha PyCharm users might experience slow performance with `Literal` overloads (issue PY-40997). If this occurs, `boto3-stubs-lite` is suggested as a more RAM-friendly alternative (though it requires more explicit type annotations), or disabling PyCharm's type checker and relying on an external tool like MyPy or Pyright.
Install
-
pip install boto3 mypy-boto3-iotevents
Imports
- IoTEventsClient
from mypy_boto3_iotevents import IoTEventsClient
- ListDetectorModelsResponseTypeDef
from mypy_boto3_iotevents.type_defs import ListDetectorModelsResponseTypeDef
Quickstart
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}")