mypy-boto3-iot-data

1.42.3 · active · verified Sat Apr 11

mypy-boto3-iot-data provides type annotations for the `boto3` IoTDataPlane service, enhancing developer experience with static type checking, auto-completion, and error prevention in IDEs like VSCode and PyCharm. It is generated by `mypy-boto3-builder` and is currently at version 1.42.3, corresponding to boto3 version 1.42.3. The `mypy-boto3` project actively maintains these stubs with frequent updates following `boto3` releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted `IoTDataPlaneClient` using `boto3` and perform a `publish` operation. The `TYPE_CHECKING` guard is used to ensure the stub imports are only active during static analysis, preventing runtime dependencies. Type definitions for request payloads (like `PublishRequestRequestTypeDef`) enhance type safety.

import boto3
from typing import TYPE_CHECKING
import os

if TYPE_CHECKING:
    from mypy_boto3_iot_data.client import IoTDataPlaneClient
    from mypy_boto3_iot_data.type_defs import PublishRequestRequestTypeDef

AWS_REGION = os.environ.get('AWS_REGION', 'us-east-1')

def get_iot_data_client() -> 'IoTDataPlaneClient':
    """Returns a type-hinted IoTDataPlane client."""
    # Actual runtime client is from boto3
    return boto3.client('iot-data', region_name=AWS_REGION)

client = get_iot_data_client()

# Example of a type-hinted request payload
publish_payload: 'PublishRequestRequestTypeDef' = {
    'topic': 'my/test/topic',
    'qos': 0,
    'payload': b'Hello from mypy-boto3-iot-data!',
}

try:
    # mypy will now provide type checking for 'publish' arguments
    response = client.publish(**publish_payload)
    print(f"Successfully published message. Response: {response}")
except Exception as e:
    print(f"Error publishing message: {e}")

view raw JSON →