mypy-boto3-mediaconvert Type Annotations

1.42.88 · active · verified Sat Apr 11

mypy-boto3-mediaconvert provides type annotations for the boto3 MediaConvert service, enhancing static analysis and IDE support for Python developers working with AWS. It ensures early error detection and improved code readability. This package is part of the larger `mypy-boto3-builder` ecosystem, which frequently releases updates in sync with `boto3` versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-mediaconvert` for type-hinting a boto3 MediaConvert client. It shows how to import the client type and associated TypedDicts for request and response structures, enabling static analysis and IDE autocompletion. Ensure `boto3` is installed and AWS credentials are configured.

import os
from typing import TYPE_CHECKING, Dict, Any
import boto3

# These imports are only for type checking, not for runtime execution
if TYPE_CHECKING:
    from mypy_boto3_mediaconvert.client import MediaConvertClient
    from mypy_boto3_mediaconvert.type_defs import CreateJobRequestTypeDef, CreateJobResponseTypeDef

def create_sample_job(role_arn: str, s3_input_url: str, s3_output_bucket: str) -> Dict[str, Any]:
    # In a real application, consider using AWS credentials from environment variables
    # or ~/.aws/credentials. For quickstart, we assume they are configured.
    
    # The client variable is explicitly typed for static analysis
    client: 'MediaConvertClient' = boto3.client("mediaconvert", region_name=os.environ.get('AWS_REGION', 'us-east-1'))

    job_settings: Dict[str, Any] = {
        "Inputs": [
            {
                "AudioSelectors": {"Audio Selector 1": {"DefaultSelection": "DEFAULT"}},
                "FileInput": s3_input_url,
            }
        ],
        "OutputGroups": [
            {
                "Name": "File Group",
                "OutputGroupSettings": {
                    "Type": "FILE_GROUP_SETTINGS",
                    "FileGroupSettings": {"Destination": f"s3://{s3_output_bucket}/"},
                },
                "Outputs": [
                    {
                        "ContainerSettings": {"Container":"MP4","Mp4Settings":{}},
                        "VideoDescription": {"CodecSettings": {"Codec": "H_264"}},
                        "AudioDescriptions": [
                            {"CodecSettings": {"Codec": "AAC"}}
                        ],
                    }
                ],
            }
        ],
    }

    request_params: 'CreateJobRequestTypeDef' = {
        "Role": role_arn,
        "Settings": job_settings,
        "Queue": os.environ.get('MEDIACONVERT_QUEUE_ARN', 'arn:aws:mediaconvert:us-east-1:123456789012:queues/Default')
    }

    try:
        response: 'CreateJobResponseTypeDef' = client.create_job(**request_params)
        print("Successfully created MediaConvert job.")
        print(f"Job ID: {response['Job']['Id']}")
        return response
    except client.exceptions.BadRequestException as e:
        print(f"Bad request: {e}")
        raise
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
        raise

if __name__ == "__main__":
    # Example usage: Replace with actual values and ensure AWS credentials/config are set.
    # For a runnable example, you need a valid AWS account, MediaConvert permissions,
    # an S3 input file, an S3 output bucket, and a MediaConvert queue.
    # Using placeholder environment variables for demonstration.
    ROLE_ARN = os.environ.get('MEDIACONVERT_ROLE_ARN', 'arn:aws:iam::123456789012:role/MediaConvertRole')
    S3_INPUT_URL = os.environ.get('S3_INPUT_VIDEO_URL', 's3://your-input-bucket/input.mp4')
    S3_OUTPUT_BUCKET = os.environ.get('S3_OUTPUT_BUCKET', 'your-output-bucket')

    if not all([ROLE_ARN, S3_INPUT_URL, S3_OUTPUT_BUCKET, os.environ.get('AWS_REGION'), os.environ.get('MEDIACONVERT_QUEUE_ARN')]):
        print("Warning: Please set MEDIACONVERT_ROLE_ARN, S3_INPUT_VIDEO_URL, S3_OUTPUT_BUCKET, AWS_REGION, and MEDIACONVERT_QUEUE_ARN environment variables for a real test.")
        print("Using dummy values for demonstration.")
        # Proceed with dummy values for type checking demonstration even if not runnable
        _ = create_sample_job(ROLE_ARN, S3_INPUT_URL, S3_OUTPUT_BUCKET)
    else:
        create_sample_job(ROLE_ARN, S3_INPUT_URL, S3_OUTPUT_BUCKET)

view raw JSON →