mypy-boto3-mediapackagev2 Type Annotations

1.42.75 · active · verified Sat Apr 11

mypy-boto3-mediapackagev2 provides type annotations for the AWS boto3 MediapackageV2 service, generated by the mypy-boto3-builder tool. It allows static type checkers like Mypy, Pyright, and IDEs to provide auto-completion and error detection for boto3 MediapackageV2 client interactions. The library is actively maintained, with frequent updates tied to `mypy-boto3-builder` releases, ensuring compatibility with the latest boto3 versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `mediapackagev2` client with explicit type annotations and use a typed `TypeDef` for input parameters, which enables static analysis for method calls like `create_channel`. Replace placeholder AWS credentials and ensure your AWS environment is configured for actual execution. The `TYPE_CHECKING` block ensures type imports are only active during type checking, avoiding runtime import issues for stub-only packages.

import boto3
import os
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_mediapackagev2.client import MediaPackageV2Client
    from mypy_boto3_mediapackagev2.type_defs import CreateChannelRequestTypeDef, ChannelTypeDef

# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# For quickstart, using dummy values for illustrative purposes
aws_access_key_id = os.environ.get('AWS_ACCESS_KEY_ID', 'AKIAIOSFODNN7EXAMPLE')
aws_secret_access_key = os.environ.get('AWS_SECRET_ACCESS_KEY', 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY')
aws_region = os.environ.get('AWS_REGION', 'us-east-1')

def create_test_channel(channel_id: str, channel_group_id: str) -> 'ChannelTypeDef':
    client: MediaPackageV2Client = boto3.client(
        'mediapackagev2',
        aws_access_key_id=aws_access_key_id,
        aws_secret_access_key=aws_secret_access_key,
        region_name=aws_region
    )

    channel_config: CreateChannelRequestTypeDef = {
        'ChannelName': channel_id,
        'ChannelGroupName': channel_group_id,
        'InputType': 'CMAF',
        'Tags': {'Environment': 'dev', 'Project': 'quickstart'}
    }

    response = client.create_channel(**channel_config)
    print(f"Channel '{response['ChannelName']}' created with ARN: {response['Arn']}")
    return response

if __name__ == '__main__':
    # This part would typically be mocked or run against a dev AWS account
    # to avoid actual resource creation/cost.
    try:
        # Example: Attempt to create a channel (this will likely fail without real creds/perms)
        # and without a pre-existing Channel Group.
        print("Attempting to create a MediaPackageV2 channel...")
        created_channel = create_test_channel("my-test-channel-123", "my-test-channel-group")
        # In a real scenario, you'd process 'created_channel' further.

    except Exception as e:
        print(f"An error occurred (expected without valid AWS setup): {e}")
        print("Please ensure 'boto3' is installed and AWS credentials/permissions are correctly configured.")

view raw JSON →