Type annotations for boto3 IoT service

1.42.14 · active · verified Sat Apr 11

mypy-boto3-iot provides comprehensive type annotations for the AWS boto3 IoT service, enhancing static analysis, autocompletion, and error detection in Python projects. It is currently at version 1.42.14, generated with mypy-boto3-builder 8.12.0, and follows a release cadence aligned with boto3 updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an IoT client with type annotations and perform a basic operation like listing IoT things. It uses `TYPE_CHECKING` for conditional imports, ensuring the type stubs are only used during type checking.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_iot import IoTClient
    from mypy_boto3_iot.type_defs import ListThingsResponseTypeDef

def list_iot_things(region_name: str = 'us-east-1') -> ListThingsResponseTypeDef:
    # Initialize the boto3 client (type-checked by mypy-boto3-iot)
    client: IoTClient = boto3.client('iot', region_name=region_name)
    
    # Example operation: List IoT Things
    response = client.list_things(maxResults=10)
    
    print(f"Found {len(response.get('things', []))} IoT things.")
    for thing in response.get('things', []):
        print(f" - {thing['thingName']}")
        
    return response

if __name__ == '__main__':
    # This assumes AWS credentials are set up (e.g., via environment variables or ~/.aws/credentials)
    try:
        list_iot_things()
    except Exception as e:
        print(f"Error listing IoT things: {e}")

view raw JSON →