Type Annotations for Boto3 MediaConnect
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
- breaking Support for Python 3.8 was removed from `mypy-boto3-builder` version 8.12.0, meaning `mypy-boto3-mediaconnect` packages generated by this builder version or newer will not support Python 3.8.
- breaking There were breaking changes in `TypeDef` naming conventions in `mypy-boto3-builder` version 8.9.0. Specifically, `TypeDef` names for packed method arguments became shorter (e.g., `CreateDistributionRequestRequestTypeDef` to `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were moved to the end.
- gotcha This package provides *only* type stubs. For your code to run, you must also install the `boto3` library, as `mypy-boto3-mediaconnect` does not include the runtime implementation.
- gotcha To avoid making `mypy-boto3-mediaconnect` a runtime dependency, which is unnecessary overhead, always wrap your type imports within a `if TYPE_CHECKING:` block.
- gotcha For optimal IDE autocompletion and type checking (especially in VSCode), it is recommended to explicitly annotate the client object when creating it, e.g., `client: MediaConnectClient = boto3.client("mediaconnect")`.
Install
-
pip install mypy-boto3-mediaconnect -
pip install boto3
Imports
- MediaConnectClient
from mypy_boto3_mediaconnect.client import MediaConnectClient
- FlowSummaryTypeDef
from mypy_boto3_mediaconnect.type_defs import FlowSummaryTypeDef
Quickstart
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()