Type Annotations for boto3 IoTAnalytics
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
- breaking Python 3.8 is no longer supported across `mypy-boto3` packages. Projects targeting Python 3.8 will need to upgrade to Python 3.9 or newer.
- breaking The `mypy-boto3-builder` introduced breaking changes to `TypeDef` naming conventions (e.g., shorter names, postfix changes) in version 8.9.0. This can affect existing type annotations in your code if you explicitly reference `TypeDef` names.
- gotcha The `mypy-boto3` ecosystem migrated to PEP 561 packages. This might impact how packages are installed or discovered, especially in custom build environments or older package managers.
- gotcha PyCharm users might experience slow performance or high CPU usage due to how it handles `Literal` overloads in `mypy-boto3`.
- gotcha While `mypy-boto3` aims for auto-discovery, explicit type annotations for `boto3.client()` and `boto3.resource()` calls are often necessary or recommended for full IDE auto-completion and static analysis support, especially in VSCode.
Install
-
pip install mypy-boto3-iotanalytics boto3 mypy
Imports
- IoTAnalyticsClient
from mypy_boto3_iotanalytics import IoTAnalyticsClient
- ListChannelsResponseTypeDef
from mypy_boto3_iotanalytics.type_defs import ListChannelsResponseTypeDef
- boto3.client('iotanalytics')
client: IoTAnalyticsClient = boto3.client('iotanalytics')
Quickstart
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}")