mypy-boto3-mediapackagev2 Type Annotations
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
- breaking Python 3.8 support has been removed in `mypy-boto3-builder` version 8.12.0 and subsequent generated packages. This library now requires Python 3.9 or newer.
- breaking The `mypy-boto3-builder` migrated to PEP 561 compliant packages with version 8.12.0. While this improves discoverability for type checkers, it might require ensuring your `mypy` configuration correctly finds installed stub packages.
- breaking Starting with `mypy-boto3-builder` 8.9.0, there were breaking changes in TypedDict naming conventions, primarily shortening redundant suffixes (e.g., `RequestRequestTypeDef` became `RequestTypeDef`) and moving `Extra` suffixes.
- gotcha This package provides *only* type annotations (stubs). It does not include the actual `boto3` library. You must install `boto3` separately for your code to function at runtime.
- gotcha For optimal IDE auto-completion and static analysis, explicitly type `boto3.client()` calls with the service-specific client class (e.g., `client: MediaPackageV2Client = boto3.client('mediapackagev2')`). Without explicit typing, `mypy` might infer a generic `botocore.client.BaseClient`, reducing type safety.
Install
-
pip install boto3 mypy-boto3-mediapackagev2
Imports
- MediaPackageV2Client
from mypy_boto3_mediapackagev2.client import MediaPackageV2Client
- CreateChannelRequestTypeDef
from mypy_boto3_mediapackagev2.type_defs import CreateChannelRequestTypeDef
Quickstart
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.")