Type Annotations for Boto3 MediaConnect

1.42.87 · active · verified Sat Apr 11

mypy-boto3-mediaconnect provides type annotations for the boto3 MediaConnect service, enhancing static analysis and IDE autocompletion for AWS MediaConnect clients. It is part of the `mypy-boto3` family of packages, currently at version 1.42.87, and is actively maintained with frequent updates mirroring boto3 releases, generated by `mypy-boto3-builder`.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-mediaconnect` to add type hints to your boto3 MediaConnect client. It initializes a typed client and lists available MediaConnect flows, leveraging the `TYPE_CHECKING` guard to prevent runtime dependency on the stub package. Remember to have `boto3` installed and AWS credentials configured for actual execution.

from typing import TYPE_CHECKING
import boto3
import os

if TYPE_CHECKING:
    from mypy_boto3_mediaconnect.client import MediaConnectClient
    from mypy_boto3_mediaconnect.type_defs import ListFlowsResponseTypeDef

# Ensure AWS credentials are set up (e.g., via environment variables or ~/.aws/credentials)
# For example, by setting AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

def list_mediaconnect_flows() -> list[str]:
    try:
        # The type annotation helps your IDE and static checker understand the client's methods
        client: MediaConnectClient = boto3.client(
            "mediaconnect",
            aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
            aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
            region_name=os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
        )
        response: ListFlowsResponseTypeDef = client.list_flows()
        flow_names = [flow['Name'] for flow in response.get('Flows', []) if 'Name' in flow]
        print(f"Found MediaConnect flows: {flow_names}")
        return flow_names
    except Exception as e:
        print(f"Error listing MediaConnect flows: {e}")
        return []

if __name__ == "__main__":
    list_mediaconnect_flows()

view raw JSON →