mypy-boto3-mediapackage: Type Annotations for AWS MediaPackage
mypy-boto3-mediapackage provides type annotations for the boto3 MediaPackage 1.42.3 service. It enables static type checking for AWS MediaPackage clients within Python applications, enhancing code quality and developer experience. The library is generated by `mypy-boto3-builder` and is actively maintained with frequent updates, often aligning with new boto3 releases and builder improvements.
Warnings
- breaking Python 3.8 support has been officially removed. Users on Python 3.8 or older must upgrade to Python 3.9 or newer to use versions 8.12.0+ of `mypy-boto3-builder` generated stubs.
- breaking The `mypy-boto3` ecosystem migrated to PEP 561 compliant packages. While generally an improvement, this might affect how `mypy` discovers stubs in certain environments or custom build setups.
- breaking Breaking changes were introduced to TypeDef naming conventions. Specifically, `CreateDistributionRequestRequestTypeDef` was shortened to `CreateDistributionRequestTypeDef`, and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`).
- gotcha For optimal type checking and IDE autocompletion, it is highly recommended to explicitly type annotate `boto3.client()` and `boto3.resource()` calls with the specific `mypy-boto3` client or resource type (e.g., `client: MediaPackageClient = session.client('mediapackage')`). While `mypy` can often infer types, explicit annotation provides the most robust experience.
- gotcha The `Session.client` and global `boto3.client` methods gained an `aws_account_id` argument. This new feature allows specifying the AWS account ID when creating a client, which can be useful for certain cross-account operations or internal tooling.
Install
-
pip install mypy-boto3-mediapackage boto3 -
pip install 'boto3-stubs[mediapackage]' mypy
Imports
- MediaPackageClient
from mypy_boto3_mediapackage.client import MediaPackageClient
- MediaPackageServiceName
from mypy_boto3_mediapackage.literals import MediaPackageServiceName
- Session
from boto3.session import Session
Quickstart
import os
from boto3.session import Session
from mypy_boto3_mediapackage.client import MediaPackageClient
# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# For example: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME
# Using os.environ.get for example purposes, in real apps boto3 handles credentials automatically.
if not os.environ.get('AWS_ACCESS_KEY_ID'):
print("Warning: AWS_ACCESS_KEY_ID not set. Quickstart might fail if credentials are not configured.")
session = Session()
# Explicitly type the client for full type-hinting and autocompletion
mediapackage_client: MediaPackageClient = session.client("mediapackage")
# Example: List origin endpoints (replace with an actual method if needed)
try:
response = mediapackage_client.list_origin_endpoints()
print("Successfully listed MediaPackage origin endpoints.")
for endpoint in response.get('OriginEndpoints', []):
print(f" - Endpoint ID: {endpoint.get('Id')}, ARN: {endpoint.get('Arn')}")
except Exception as e:
print(f"Error listing origin endpoints: {e}")