{"id":3374,"library":"mypy-boto3-polly","title":"mypy-boto3-polly Type Stubs","description":"mypy-boto3-polly provides type annotations for the boto3 Polly service. It offers comprehensive type hints for Polly clients, paginators, and specific type definitions, which enhances static analysis with tools like mypy, PyCharm, and VSCode. The package is automatically generated by `mypy-boto3-builder` and is regularly updated to stay compatible with `boto3` releases.","status":"active","version":"1.42.76","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","mypy","type-stubs","polly","typing","static-analysis"],"install":[{"cmd":"pip install boto3 mypy-boto3-polly","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Runtime dependency for the type stubs to be functional, as this package only provides type annotations, not the implementation.","package":"boto3"},{"reason":"The primary type checker for which these stubs are designed. Other type checkers like Pyright also benefit.","package":"mypy","optional":true}],"imports":[{"note":"While `boto3.client('polly')` returns a client object, directly importing `PollyClient` from `boto3.client` does not provide the specific type hints. The `mypy-boto3-polly` package provides the fully typed `PollyClient`.","wrong":"from boto3.client import PollyClient","symbol":"PollyClient","correct":"from mypy_boto3_polly.client import PollyClient"},{"symbol":"DescribeVoicesPaginator","correct":"from mypy_boto3_polly.paginator import DescribeVoicesPaginator"},{"symbol":"AudioEventTypeDef","correct":"from mypy_boto3_polly.type_defs import AudioEventTypeDef"}],"quickstart":{"code":"import boto3\nfrom mypy_boto3_polly.client import PollyClient\nfrom mypy_boto3_polly.type_defs import SynthesizeSpeechOutputTypeDef\nimport os\n\n\ndef synthesize_and_save(text: str, output_path: str):\n    # Ensure AWS credentials are available (e.g., via environment variables or ~/.aws/credentials)\n    # For local testing, ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION are set.\n\n    # Explicitly type the client for full type-checking benefits\n    client: PollyClient = boto3.client(\"polly\", region_name=os.environ.get('AWS_REGION', 'us-east-1'))\n\n    response: SynthesizeSpeechOutputTypeDef = client.synthesize_speech(\n        Text=text,\n        OutputFormat='mp3',\n        VoiceId='Joanna'\n    )\n\n    # In a real application, handle the 'AudioStream' which is a StreamingBody\n    # For this quickstart, we'll just demonstrate the typing of the response.\n    if response['AudioStream']:\n        print(f\"Successfully received audio stream with content type: {response['ContentType']}\")\n        # Example: to save to a file (simplified, error handling omitted)\n        # with open(output_path, 'wb') as f:\n        #     f.write(response['AudioStream'].read())\n        # print(f\"Audio saved to {output_path}\")\n    else:\n        print(\"No audio stream received.\")\n\n# Example usage (requires AWS setup for actual execution)\n# synthesize_and_save(\"Hello, world! This is a typed Polly client example.\", \"output.mp3\")\nprint(\"Quickstart code demonstrates type hinting for boto3 Polly client.\")\n","lang":"python","description":"This quickstart demonstrates how to use the `mypy-boto3-polly` type stubs with a standard boto3 client. It explicitly types the Polly client and its response, allowing type checkers to validate usage and provide intelligent autocomplete."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 or older will need to upgrade their Python version.","severity":"breaking","affected_versions":">=8.12.0"},{"fix":"Review and update TypeDef imports and usage in your codebase to match the new naming conventions. Consult the `mypy-boto3-polly` documentation for the correct TypeDef names.","message":"TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. This led to shorter names for packed method arguments (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`) and reordered suffixes for conflicting TypeDefs. Code relying on exact TypeDef names may break.","severity":"breaking","affected_versions":">=8.9.0"},{"fix":"Always ensure `boto3` is installed in the same environment as `mypy-boto3-polly` (e.g., `pip install boto3 mypy-boto3-polly`).","message":"`mypy-boto3-polly` is a stub-only package (PEP 561). It *must* be installed alongside the `boto3` library itself. Mypy and IDEs will automatically find these stubs, but if `boto3` is not present, the type stubs will have no implementation to apply to.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When creating a client, explicitly add the type annotation: `client: PollyClient = boto3.client(\"polly\")`.","message":"For optimal autocomplete and type checking in some IDEs (especially older versions of PyCharm or VSCode without the Pylance extension), it is recommended to explicitly type your `boto3.client()` calls, even with stubs installed.","severity":"gotcha","affected_versions":"All versions, depends on IDE/type checker configuration"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}