mypy-boto3-iotevents-data type annotations
mypy-boto3-iotevents-data provides type annotations for the `boto3` IoTEventsData service, ensuring type safety and improved autocompletion for Python developers. It is currently at version 1.42.3 and is part of the `mypy-boto3` family, with new releases frequently generated by `mypy-boto3-builder` to stay in sync with `boto3` updates.
Warnings
- breaking Python 3.8 support was removed with `mypy-boto3-builder` version 8.12.0 for all generated packages, including `mypy-boto3-iotevents-data`. Ensure your project uses Python 3.9 or newer.
- breaking The underlying `mypy-boto3-builder` (v8.9.0) introduced breaking changes in `TypeDef` naming conventions. Packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and conflicting `TypeDef` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).
- breaking The `mypy-boto3-builder` (v8.12.0) migrated to PEP 561 compliant packages. While this is generally beneficial, it might cause subtle changes in how type checkers discover or interact with the stubs, especially in complex project setups.
- gotcha This library provides *type annotations* only. You must also install `boto3` (or `aiobotocore`/`aioboto3` for async variants) for the actual AWS SDK runtime functionality. Without `boto3` installed, your code will fail at runtime.
- gotcha For standalone `mypy-boto3-*` packages like this one, explicit type annotations for clients (e.g., `client: IoTEventsDataClient = session.client(...)`) are generally required for full IDE autocompletion and `mypy` functionality. Implicit typing might not work as expected.
- gotcha PyCharm users might experience slow performance with `Literal` overloads due to a known IDE issue (PY-40997). For better performance, consider using `boto3-stubs-lite` or external type checkers like `mypy` or `pyright`.
Install
-
pip install mypy-boto3-iotevents-data boto3 mypy
Imports
- IoTEventsDataClient
from mypy_boto3_iotevents_data.client import IoTEventsDataClient
- IoTEventsDataServiceResource
from mypy_boto3_iotevents_data.service_resource import IoTEventsDataServiceResource
- PutMessageRequestRequestTypeDef
from mypy_boto3_iotevents_data.type_defs import PutMessageRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_iotevents_data.client import IoTEventsDataClient
from mypy_boto3_iotevents_data.type_defs import PutMessageRequestRequestTypeDef
import os
def send_iot_event_data(event_data: PutMessageRequestRequestTypeDef) -> dict:
session = boto3.Session(region_name=os.environ.get('AWS_REGION', 'us-east-1'))
client: IoTEventsDataClient = session.client('iotevents-data')
response = client.put_message(messages=[event_data])
print(f"Sent IoT Event Data: {response}")
return response
if __name__ == "__main__":
# Example usage - replace with actual event data
# In a real scenario, you'd populate this with data for your detector model.
sample_event = {
"messageId": "my-unique-message-id",
"inputName": "my-input",
"payload": b'{"temperature": 25.5}' # Payload must be bytes
}
try:
# Ensure AWS_REGION is set in environment, or provide it directly
os.environ['AWS_REGION'] = os.environ.get('AWS_REGION', 'us-east-1')
send_iot_event_data(sample_event)
except Exception as e:
print(f"Error sending IoT Event Data: {e}")