mypy-boto3-ivs-realtime

1.42.86 · active · verified Sat Apr 11

mypy-boto3-ivs-realtime provides comprehensive type annotations for the AWS IVS Realtime service within the boto3 library. Currently at version 1.42.86, it is part of the mypy-boto3-builder ecosystem, which generates and releases type stubs frequently, often in sync with new boto3 releases, ensuring up-to-date type checking for AWS services.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up an IVS Real-time client with type annotations and generate a participant token. It uses `TYPE_CHECKING` for conditional import of stubs, ensuring they are only used during type checking. The client is explicitly typed to leverage the full capabilities of `mypy-boto3-ivs-realtime`. Replace placeholder values with actual AWS credentials and a valid IVS Real-time channel ARN.

import boto3
import os
from typing import TYPE_CHECKING

# Only import type stubs when type checking
if TYPE_CHECKING:
    from mypy_boto3_ivs_realtime.client import IVSRealTimeClient
    from mypy_boto3_ivs_realtime.type_defs import CreateParticipantTokenResponseTypeDef


def get_participant_token(channel_arn: str, user_id: str) -> dict:
    """Generates a participant token for an IVS Real-time channel."""
    # Explicitly type the client for mypy to provide full benefits
    client: 'IVSRealTimeClient' = boto3.client(
        'ivs-realtime',
        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )

    response: 'CreateParticipantTokenResponseTypeDef' = client.create_participant_token(
        channelArn=channel_arn,
        userId=user_id
    )
    return response

# Example usage (will not run without AWS credentials and a valid channel ARN)
if __name__ == "__main__":
    EXAMPLE_CHANNEL_ARN = os.environ.get('IVS_REALTIME_CHANNEL_ARN', 'arn:aws:ivs:us-east-1:123456789012:channel/abcdefghijkL')
    EXAMPLE_USER_ID = 'test-user-123'

    print(f"Attempting to get participant token for channel: {EXAMPLE_CHANNEL_ARN}, user: {EXAMPLE_USER_ID}")
    try:
        # This call will fail without actual AWS credentials and a valid ARN
        token_info = get_participant_token(EXAMPLE_CHANNEL_ARN, EXAMPLE_USER_ID)
        print("Successfully received token info (type-checked):")
        print(token_info)
    except Exception as e:
        print(f"Error generating token: {e}")
        print("Please ensure AWS credentials and a valid IVS Real-time channel ARN are set as environment variables.")

view raw JSON →