mypy-boto3-transcribe
mypy-boto3-transcribe provides type annotations for the boto3 Transcribe service, specifically for version 1.42.25 of boto3. These packages are automatically generated by `mypy-boto3-builder` and are released frequently to keep up with boto3 updates, offering precise type hints for clients, resources, and various TypeDefs.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generates these stub packages), Python 3.8 is no longer supported. Additionally, all generated packages migrated to PEP 561, which might affect environments relying on older packaging patterns.
- gotcha When using `mypy-boto3` for a specific service like Transcribe, you generally need to install the service-specific stub package (e.g., `mypy-boto3-transcribe`). Installing just `mypy-boto3` provides stubs for all services but can be a significantly larger dependency.
- gotcha To leverage type hints, you must cast the `boto3.client()` return value to the specific `mypy-boto3` client type (e.g., `TranscribeClient`). Without the `cast`, `mypy` will only see the untyped `botocore.client.Client`.
- gotcha The `mypy-boto3-*` packages are generated based on specific `boto3` and underlying `botocore` versions. Using an older stub package with a newer `boto3` version (or vice-versa) can lead to incorrect or missing type hints, as the API might have changed.
- breaking From `mypy-boto3-builder` version 8.9.0, there were breaking changes in `TypeDef` naming conventions. For instance, `CreateDistributionRequestRequestTypeDef` was shortened to `CreateDistributionRequestTypeDef`, and `Extra` postfixes moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`).
Install
-
pip install mypy-boto3-transcribe -
pip install mypy-boto3
Imports
- TranscribeClient
from mypy_boto3_transcribe.client import TranscribeClient
- ListTranscriptionJobsPaginator
from mypy_boto3_transcribe.paginator import ListTranscriptionJobsPaginator
- TranscriptionJobSummaryTypeDef
from mypy_boto3_transcribe.type_defs import TranscriptionJobSummaryTypeDef
Quickstart
import boto3
from mypy_boto3_transcribe.client import TranscribeClient
from typing import TYPE_CHECKING, cast
import os
# Boto3 client requires AWS credentials, which can be configured via
# environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION)
# or other boto3 configuration methods.
if TYPE_CHECKING:
# This block is only for type checking tools like mypy or pyright.
# It helps prevent runtime import issues and ensures correct type resolution.
pass
def get_typed_transcribe_client() -> TranscribeClient:
"""Returns a type-hinted boto3 Transcribe client."""
# boto3.client returns a DynamicClient which is untyped.
# We cast it to the specific mypy-boto3-transcribe client type.
client = boto3.client("transcribe", region_name=os.environ.get('AWS_REGION', 'us-east-1'))
return cast(TranscribeClient, client)
# --- Example Usage ---
transcribe_client = get_typed_transcribe_client()
print("Listing first 3 transcription jobs:")
response = transcribe_client.list_transcription_jobs(
MaxResults=3,
Status='COMPLETED' # Example filter
)
job_summaries = response.get("TranscriptionJobSummaries", [])
if job_summaries:
for job in job_summaries:
print(f" - Name: {job['TranscriptionJobName']}, Status: {job['TranscriptionJobStatus']}")
else:
print(" No completed transcription jobs found.")
# mypy will now correctly check arguments and return types for methods of transcribe_client
# e.g., transcribe_client.start_transcription_job(TranscriptionJobName=123) will be flagged
# as TranscriptionJobName expects a string.