{"id":3642,"library":"mypy-boto3-mturk","title":"mypy-boto3-mturk Type Annotations","description":"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`.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["mypy","boto3","aws","typing","stubs","mturk","type-annotations"],"install":[{"cmd":"pip install boto3 mypy-boto3-mturk","lang":"bash","label":"Install with boto3"}],"dependencies":[{"reason":"Required Python version.","package":"python","version":">=3.9"},{"reason":"Provides the AWS SDK for Python; this library only provides type annotations.","package":"boto3","version":">=1.42.3"}],"imports":[{"note":"Client types are typically located in the `.client` submodule for `mypy-boto3` packages.","wrong":"from mypy_boto3_mturk import MTurkClient","symbol":"MTurkClient","correct":"from mypy_boto3_mturk.client import MTurkClient"},{"note":"Literals for service names are useful for explicit type hinting in `boto3.client` calls.","symbol":"MTurkServiceName","correct":"from mypy_boto3_mturk.literals import MTurkServiceName"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING\n\nif TYPE_CHECKING:\n    from mypy_boto3_mturk.client import MTurkClient\n\ndef get_mturk_client() -> MTurkClient:\n    \"\"\"Returns a type-hinted MTurk client.\"\"\"\n    # boto3.client returns botocore.client.BaseClient at runtime,\n    # but mypy will correctly infer MTurkClient type from the annotation.\n    client: MTurkClient = boto3.client('mturk')\n    return client\n\n# Example usage:\nmturk_client = get_mturk_client()\n# Now mturk_client has type hints for MTurk service methods\n# For example, mturk_client.list_hits() will have correct type signatures.\n\n# This is a runnable example, but it requires valid AWS credentials\n# and an active MTurk environment for actual API calls.\n# print(mturk_client.list_hits()) # Uncomment to run actual API call","lang":"python","description":"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."},"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. Consequently, `mypy-boto3-mturk` versions generated with this builder (including 1.42.3) and newer require Python 3.9 or higher.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.12.0, mypy-boto3-mturk >=1.42.3"},{"fix":"Review your code for TypeDef imports and update names according to the new conventions. Consult the `mypy-boto3-builder` release notes for specific changes.","message":"In `mypy-boto3-builder` 8.9.0, there were breaking changes to TypeDef naming conventions, particularly for packed method arguments and conflicting names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`).","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.9.0, mypy-boto3-mturk built with these versions"},{"fix":"Ensure `pip install boto3` is executed in your environment alongside `mypy-boto3-mturk`.","message":"`mypy-boto3-mturk` provides *only type annotations*. It does not include the `boto3` library itself. You must install `boto3` separately to use the AWS SDK at runtime.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always add explicit type hints like `client: MTurkClient = boto3.client('mturk')`.","message":"When using standalone `mypy-boto3-*` packages or `boto3-stubs-lite`, explicit type annotations for `boto3.client` and `boto3.resource` calls are often required for optimal type inference.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider `pip install boto3-stubs-lite[mturk]` or use custom generated stubs for improved IDE performance.","message":"PyCharm users might experience slow performance with `Literal` overloads. It is recommended to use the `boto3-stubs-lite` packages or generate custom stubs locally with `mypy-boto3-builder` to mitigate this issue.","severity":"gotcha","affected_versions":"All versions (specifically with PyCharm IDE)"},{"fix":"Implement `if TYPE_CHECKING: from mypy_boto3_mturk.client import MTurkClient else: MTurkClient = object`.","message":"For `pylint` compatibility, especially when `mypy-boto3-mturk` is not a runtime dependency, use a `TYPE_CHECKING` guard around type imports and assign `object` to types in the `else` block to avoid `undefined variable` errors from `pylint`.","severity":"gotcha","affected_versions":"All versions (when using pylint without runtime stub dependency)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}