{"id":3160,"library":"mypy-boto3-translate","title":"mypy-boto3-translate Type Stubs","description":"mypy-boto3-translate provides comprehensive type annotations for the AWS boto3 Translate service, enhancing development with static type checking. It is generated by the mypy-boto3-builder, ensuring alignment with boto3's API definitions. The current version is 1.42.3, typically updated frequently to match new boto3 releases and builder improvements.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["mypy","boto3","aws","type-hints","stubs","translate","static-analysis"],"install":[{"cmd":"pip install mypy-boto3-translate","lang":"bash","label":"Install type stubs"},{"cmd":"pip install boto3","lang":"bash","label":"Install boto3 (runtime dependency)"}],"dependencies":[{"reason":"Provides the runtime AWS SDK that these type stubs annotate. Must be installed separately.","package":"boto3","optional":false},{"reason":"The primary static type checker for which these stubs are designed.","package":"mypy","optional":true}],"imports":[{"symbol":"TranslateClient","correct":"from mypy_boto3_translate.client import TranslateClient"},{"symbol":"TranslateTextRequestRequestTypeDef","correct":"from mypy_boto3_translate.type_defs import TranslateTextRequestRequestTypeDef"},{"symbol":"TranslateTextResponseTypeDef","correct":"from mypy_boto3_translate.type_defs import TranslateTextResponseTypeDef"},{"symbol":"JobStatusType","correct":"from mypy_boto3_translate.literals import JobStatusType"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING, Dict, Any\n\n# These imports are only for type checking and are typically guarded\n# to prevent runtime errors if the stub package is not installed.\nif TYPE_CHECKING:\n    from mypy_boto3_translate.client import TranslateClient\n    from mypy_boto3_translate.type_defs import (\n        TranslateTextRequestRequestTypeDef,\n        TranslateTextResponseTypeDef\n    )\n\ndef translate_text_example(text: str, source_language: str, target_language: str) -> Dict[str, Any]:\n    \"\"\"Translates text using AWS Translate service with type hints.\"\"\"\n    # Create a boto3 client. The type hint helps mypy understand its methods.\n    client: TranslateClient = boto3.client(\"translate\")\n\n    # Define the request payload with a type hint for validation.\n    request_payload: TranslateTextRequestRequestTypeDef = {\n        \"Text\": text,\n        \"SourceLanguageCode\": source_language,\n        \"TargetLanguageCode\": target_language\n        # Optional parameters can also be type-hinted and added here:\n        # 'TerminologyNames': [],\n        # 'Settings': {'Formality': 'FORMAL'}\n    }\n\n    # Call the service method. The response is also type-hinted.\n    response: TranslateTextResponseTypeDef = client.translate_text(**request_payload)\n    return response\n\nif __name__ == \"__main__\":\n    import os\n    # Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)\n    # For this example, we'll use dummy text. Boto3 will handle credential lookup.\n    # If running locally, make sure your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY\n    # are set as environment variables or configured in ~/.aws/credentials.\n\n    try:\n        translated_output = translate_text_example(\n            text=\"Hello, world! How are you today?\",\n            source_language=\"en\",\n            target_language=\"es\"\n        )\n        print(f\"Original text: Hello, world! How are you today?\")\n        print(f\"Translated text (ES): {translated_output['TranslatedText']}\")\n        # Expected output: Translated text (ES): ¡Hola, mundo! ¿Cómo estás hoy?\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n        print(\"Please ensure AWS credentials are configured and the Translate service is accessible.\")","lang":"python","description":"This quickstart demonstrates how to use `mypy-boto3-translate` with `boto3` to type-hint a client and its method calls for the Translate service. It includes type hints for both the client instance and the request/response payloads, ensuring static type safety."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer. Alternatively, pin your `mypy-boto3-translate` version to an older release if Python 3.8 support is critical.","message":"Starting with `mypy-boto3-builder` version 8.12.0 (which generates `mypy-boto3-translate` packages), Python 3.8 is no longer supported. The `requires_python` metadata is now `>=3.9`.","severity":"breaking","affected_versions":"mypy-boto3-translate >= 1.42.0 (aligning with builder 8.12.0)"},{"fix":"Update your code to use the new TypeDef names. Consult the `mypy-boto3` documentation or regenerate your stub references.","message":"The `mypy-boto3-builder` (version 8.9.0) introduced changes to generated TypeDef naming conventions. For instance, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`, and the `Extra` postfix for conflicting names moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).","severity":"breaking","affected_versions":"mypy-boto3-translate >= 1.42.0 (aligning with builder 8.9.0)"},{"fix":"Ensure `boto3` is included in your project's dependencies (e.g., `pip install boto3`).","message":"These packages provide only type stubs for `boto3`. You must install `boto3` itself separately for your application to run at runtime. `mypy-boto3-translate` does not automatically install `boto3`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install `mypy-boto3-translate` with a version that matches your `boto3` installation (e.g., if `boto3` is 1.42.3, install `mypy-boto3-translate==1.42.3`).","message":"For the most accurate type checking, it is crucial to align the version of `mypy-boto3-translate` with the version of `boto3` you are using at runtime. Mismatched versions can lead to incorrect type hints or undetected API discrepancies.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your `mypy` or other type checker is up-to-date. If encountering stub resolution issues, verify your `mypy` configuration (e.g., `mypy_path`).","message":"The `mypy-boto3` ecosystem migrated to PEP 561 package format with `mypy-boto3-builder` version 8.12.0. While this is a standard for distributing type stubs, older tooling or specific `mypy` configurations might experience changes in how stubs are discovered or resolved.","severity":"gotcha","affected_versions":"mypy-boto3-translate >= 1.42.0 (aligning with builder 8.12.0)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}