Type Annotations for boto3 PersonalizeEvents

1.42.3 · active · verified Sat Apr 11

mypy-boto3-personalize-events provides type annotations for the `boto3` PersonalizeEvents service, enabling static type checking with tools like MyPy, PyRight, and improved IDE auto-completion. It is part of the `mypy-boto3` project, which generates stubs for all `boto3` services. This package is currently at version 1.42.3, generated with `mypy-boto3-builder 8.12.0`, and follows a frequent release cadence, often aligning with `boto3` and `mypy-boto3-builder` updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `boto3` PersonalizeEvents client with explicit type hints from `mypy-boto3-personalize-events` and perform a `put_events` operation. It includes a `TYPE_CHECKING` guard to ensure the stub dependency is only active during type checking, not runtime, and uses environment variables for AWS credentials.

import boto3
import os
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_personalize_events.client import PersonalizeEventsClient
    from mypy_boto3_personalize_events.type_defs import PutEventsRequestRequestTypeDef

def process_personalize_events(session: boto3.Session) -> None:
    # Client is explicitly typed for full IDE support and static analysis
    client: PersonalizeEventsClient = session.client("personalize-events")

    # Example: Put events
    event_data: PutEventsRequestRequestTypeDef = {
        "trackingId": "your-tracking-id",
        "sessionId": "user-session-id-123",
        "eventList": [
            {
                "eventId": "event-id-1",
                "eventType": "Purchase",
                "itemId": "item-id-101",
                "sentAt": "2026-04-11T13:00:00Z",
                "properties": "{\"price\": 10.99}"
            }
        ]
    }
    
    response = client.put_events(**event_data)
    print(f"PutEvents response: {response}")

if __name__ == "__main__":
    # Use environment variables for credentials in production
    aws_session = boto3.Session(
        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )
    process_personalize_events(aws_session)

view raw JSON →