mypy-boto3-iot-data
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
- breaking Python 3.8 support has been removed since `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 or older must upgrade to Python 3.9+ to use newer versions of these stubs.
- breaking Breaking changes were introduced in `mypy-boto3-builder` version 8.9.0 regarding `TypeDef` naming conventions. Request TypeDefs for packed arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). Conflicting `TypeDef` `Extra` postfixes were also moved. This may require updating existing type hints.
- gotcha The `mypy-boto3` project migrated to PEP 561 compliant packages with `mypy-boto3-builder` version 8.12.0. While this generally improves compatibility with type checkers, ensure your `mypy` setup is configured to find installed stub packages, and you are running `mypy` in the same Python environment where `mypy-boto3-iot-data` is installed.
- gotcha When using `mypy-boto3` with `pylint`, you might encounter false positives regarding undefined variables if you use `TYPE_CHECKING` for conditional imports.
Install
-
pip install mypy-boto3-iot-data boto3
Imports
- IoTDataPlaneClient
from mypy_boto3_iot_data.client import IoTDataPlaneClient
- PublishRequestRequestTypeDef
from mypy_boto3_iot_data.type_defs import PublishRequestRequestTypeDef
- TYPE_CHECKING
from typing import TYPE_CHECKING
Quickstart
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}")