mypy-boto3-ivs-realtime
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
- breaking Python 3.8 support has been removed since `mypy-boto3-builder 8.12.0`. All generated `mypy-boto3-*` packages, including `mypy-boto3-ivs-realtime`, now require Python 3.9 or newer.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder 8.9.0`. Argument TypeDefs for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). Conflicting `Extra` postfixes were also moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`).
- gotcha This package provides *type stubs* for `boto3`. It does not include the `boto3` library itself. You must install `boto3` separately (e.g., `pip install boto3`) for your code to run at runtime.
- gotcha Explicit type annotations for `boto3.client()` calls are recommended (`client: IVSRealTimeClient = boto3.client('ivs-realtime')`). While some IDEs and `mypy` might infer types, explicit annotation ensures full type-checking benefits, especially when using `boto3-stubs-lite` or standalone service packages, and can mitigate performance issues in IDEs like PyCharm with Literal overloads.
Install
-
pip install mypy-boto3-ivs-realtime boto3
Imports
- IVSRealTimeClient
from mypy_boto3_ivs_realtime.client import IVSRealTimeClient
- IVSRealTimeClient
client: IVSRealTimeClient = boto3.client('ivs-realtime')
Quickstart
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.")