mypy-boto3-mturk Type Annotations

1.42.3 · active · verified Sat Apr 11

mypy-boto3-mturk provides comprehensive type annotations for the Amazon Mechanical Turk (MTurk) service client within the `boto3` library. It enables static type checking with tools like MyPy, improving code quality and developer experience by offering auto-completion and early error detection. The library is actively maintained, with versions typically synchronized with `boto3` releases and generated by `mypy-boto3-builder`.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a type-hinted `MTurkClient` using `boto3` and the `mypy-boto3-mturk` stubs. It uses a `TYPE_CHECKING` guard to ensure the type import is only active during static analysis, preventing runtime import errors if `mypy-boto3-mturk` is not installed in the production environment.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_mturk.client import MTurkClient

def get_mturk_client() -> MTurkClient:
    """Returns a type-hinted MTurk client."""
    # boto3.client returns botocore.client.BaseClient at runtime,
    # but mypy will correctly infer MTurkClient type from the annotation.
    client: MTurkClient = boto3.client('mturk')
    return client

# Example usage:
mturk_client = get_mturk_client()
# Now mturk_client has type hints for MTurk service methods
# For example, mturk_client.list_hits() will have correct type signatures.

# This is a runnable example, but it requires valid AWS credentials
# and an active MTurk environment for actual API calls.
# print(mturk_client.list_hits()) # Uncomment to run actual API call

view raw JSON →