{"id":3368,"library":"mypy-boto3-lex-runtime","title":"mypy-boto3-lex-runtime Type Stubs","description":"mypy-boto3-lex-runtime provides high-quality type annotations for the boto3 LexRuntimeService. Currently at version 1.42.3, this library is part of the larger mypy-boto3 project, which automatically generates stubs for all AWS services. It's updated frequently, typically aligning with new boto3 releases and enhancements in the mypy-boto3-builder.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","lex","types","mypy","type-hinting","static-analysis","cloud"],"install":[{"cmd":"pip install mypy-boto3-lex-runtime","lang":"bash","label":"Install service stubs"},{"cmd":"pip install boto3 mypy","lang":"bash","label":"Install runtime SDK and type checker"}],"dependencies":[{"reason":"Runtime dependency for the AWS SDK, which these stubs type-check.","package":"boto3"},{"reason":"Static type checker required to utilize these stubs.","package":"mypy","optional":true},{"reason":"Runtime dependency for advanced type features, often used for compatibility.","package":"typing-extensions","optional":true}],"imports":[{"symbol":"LexRuntimeServiceClient","correct":"from mypy_boto3_lex_runtime.client import LexRuntimeServiceClient"},{"symbol":"PostTextRequestRequestTypeDef","correct":"from mypy_boto3_lex_runtime.type_defs import PostTextRequestRequestTypeDef"},{"symbol":"PostTextResponseTypeDef","correct":"from mypy_boto3_lex_runtime.type_defs import PostTextResponseTypeDef"},{"note":"Without explicit type hinting, mypy cannot provide detailed type-checking for client methods, leading to 'Any' types.","wrong":"client = boto3.client(\"lex-runtime\")","symbol":"boto3.client without typing","correct":"import boto3\n# For type-checking, assign to a type-hinted variable:\nclient: LexRuntimeServiceClient = boto3.client(\"lex-runtime\")"}],"quickstart":{"code":"import os\nimport boto3\nfrom typing import TYPE_CHECKING\n\n# Import specific types only when type checking using TYPE_CHECKING guard\nif TYPE_CHECKING:\n    from mypy_boto3_lex_runtime.client import LexRuntimeServiceClient\n    from mypy_boto3_lex_runtime.type_defs import PostTextRequestRequestTypeDef, PostTextResponseTypeDef\n\n# Configure AWS credentials (for demonstration, use environment variables or default config)\n# In a real application, consider using AWS IAM roles or standard AWS configuration.\naws_access_key_id = os.environ.get(\"AWS_ACCESS_KEY_ID\", \"MOCK_ACCESS_KEY\")\naws_secret_access_key = os.environ.get(\"AWS_SECRET_ACCESS_KEY\", \"MOCK_SECRET_KEY\")\naws_region = os.environ.get(\"AWS_REGION\", \"us-east-1\")\n\n# Initialize the Lex Runtime client with type annotation.\n# The '\"LexRuntimeServiceClient\"' uses a string forward reference, common with TYPE_CHECKING.\nclient: \"LexRuntimeServiceClient\" = boto3.client(\n    \"lex-runtime\",\n    region_name=aws_region,\n    aws_access_key_id=aws_access_key_id,\n    aws_secret_access_key=aws_secret_access_key,\n)\n\n# Define request parameters using TypedDicts for type safety. \n# Replace 'YourLexBotName' with your actual Amazon Lex bot's name.\nrequest_params: \"PostTextRequestRequestTypeDef\" = {\n    \"botName\": \"YourLexBotName\", \n    \"botAlias\": \"$LATEST\",       \n    \"userId\": \"testuser123\",\n    \"inputText\": \"Hello, what is your name?\",\n}\n\n# Call a client method; mypy will check arguments and return type\nresponse: \"PostTextResponseTypeDef\" = client.post_text(**request_params)\n\nprint(f\"Lex Runtime PostText Response: {response}\")\n\n# Access typed fields from the response\nmessage_content = response.get(\"message\")\nprint(f\"Bot's message: {message_content}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize a `boto3` Lex Runtime client and make a `post_text` call with `mypy-boto3-lex-runtime` type annotations. The `TYPE_CHECKING` guard ensures that stub imports are only processed by the type checker, which can improve runtime performance and robustness if `mypy-boto3` is primarily a development dependency."},"warnings":[{"fix":"Upgrade your Python environment to version 3.9 or newer to ensure compatibility and receive updates.","message":"Python 3.8 support was officially removed with mypy-boto3-builder version 8.12.0 (released alongside mypy-boto3-lex-runtime versions around 1.30.0+). Projects still utilizing Python 3.8 will encounter compatibility issues.","severity":"breaking","affected_versions":"mypy-boto3-builder>=8.12.0"},{"fix":"Review and update your type import paths and TypeDef names according to the new conventions. The service's `type_defs.pyi` file provides the authoritative names.","message":"Type definition naming conventions were refactored in mypy-boto3-builder 8.9.0. This included shortening redundant TypeDef suffixes (e.g., `CreateDistributionRequestRequestTypeDef` to `CreateDistributionRequestTypeDef`) and moving conflicting `Extra` postfixes. This can break explicit type imports in existing codebases.","severity":"breaking","affected_versions":"mypy-boto3-builder>=8.9.0"},{"fix":"Ensure both `boto3` and `mypy` are installed in your project environment (e.g., `pip install boto3 mypy`), in addition to `mypy-boto3-lex-runtime`.","message":"These packages provide only type stubs for `boto3`. For your application to run, you must install the actual `boto3` library. For static analysis, you also need to install `mypy`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Integrate `mypy` into your project's checks. Example: `mypy your_project/`.","message":"To leverage these type stubs, you must actively run `mypy` (or another compatible static type checker) as part of your development or CI/CD workflow. The stubs themselves do not add runtime type enforcement.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your Python environment, package manager, and development tools are up-to-date and compatible with PEP 561 standards. No specific code change is typically required.","message":"The `mypy-boto3` packages migrated to the PEP 561 standard for Python type stubs with `mypy-boto3-builder` version 8.12.0. While this is a positive change for compatibility, it might affect certain older build systems or tools that had specific assumptions about non-PEP 561 package structures.","severity":"gotcha","affected_versions":"mypy-boto3-builder>=8.12.0"},{"fix":"Regularly consult `mypy-boto3` release notes for service-specific changes and update your code, imports, and API calls accordingly if using affected services.","message":"AWS services can be deprecated or renamed (e.g., `sms-voice` service was replaced by `pinpoint-sms-voice` in builder 8.11.0). While Lex Runtime is generally stable, future `mypy-boto3` versions will reflect any such changes in AWS service availability or APIs, which could break old service imports.","severity":"deprecated","affected_versions":"All versions"},{"fix":"Modify your code to import types conditionally: `from typing import TYPE_CHECKING; if TYPE_CHECKING: from mypy_boto3_lex_runtime.client import LexRuntimeServiceClient`.","message":"It is recommended to wrap `mypy-boto3` type imports in `if TYPE_CHECKING:` blocks. This prevents loading potentially large stub modules at runtime, which can be beneficial for performance and robustness if the stubs are only a development dependency.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}