Skip to content

Examples#

Index > Polly > Examples

Auto-generated documentation for Polly type annotations stubs module mypy-boto3-polly.

Client#

Implicit type annotations#

Can be used with boto3-stubs[polly] package installed.

Write your Polly code as usual, type checking and code completion should work out of the box.

# PollyClient usage example

from boto3.session import Session


session = Session()

client = session.client("polly")  # (1)
result = client.describe_voices()  # (2)
  1. client: PollyClient
  2. result: DescribeVoicesOutputTypeDef
# DescribeVoicesPaginator usage example

from boto3.session import Session


session = Session()
client = session.client("polly")  # (1)

paginator = client.get_paginator("describe_voices")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: PollyClient
  2. paginator: DescribeVoicesPaginator
  3. item: DescribeVoicesOutputTypeDef

Explicit type annotations#

With boto3-stubs-lite[polly] or a standalone mypy_boto3_polly package, you have to explicitly specify client: PollyClient type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

# PollyClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_polly.client import PollyClient
from mypy_boto3_polly.type_defs import DescribeVoicesOutputTypeDef
from mypy_boto3_polly.type_defs import DescribeVoicesInputRequestTypeDef


session = Session()

client: PollyClient = session.client("polly")

kwargs: DescribeVoicesInputRequestTypeDef = {...}
result: DescribeVoicesOutputTypeDef = client.describe_voices(**kwargs)
# DescribeVoicesPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_polly.client import PollyClient
from mypy_boto3_polly.paginator import DescribeVoicesPaginator
from mypy_boto3_polly.type_defs import DescribeVoicesOutputTypeDef


session = Session()
client: PollyClient = session.client("polly")

paginator: DescribeVoicesPaginator = client.get_paginator("describe_voices")
for item in paginator.paginate(...):
    item: DescribeVoicesOutputTypeDef
    print(item)