{"id":3615,"library":"mypy-boto3-lexv2-runtime","title":"Type Stubs for boto3 LexRuntimeV2","description":"mypy-boto3-lexv2-runtime provides static type annotations for the `boto3` LexRuntimeV2 service, generated by `mypy-boto3-builder`. It enhances type checking for your AWS `LexRuntimeV2` client interactions using `mypy`, improving code quality and catching potential errors at development time. The library releases frequently, often in sync with `boto3` and `mypy-boto3-builder` updates, with the current version being 1.42.3.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["mypy","boto3","type-stubs","aws","lexv2-runtime","static-analysis","typing"],"install":[{"cmd":"pip install mypy-boto3-lexv2-runtime boto3","lang":"bash","label":"Install with boto3 (recommended)"},{"cmd":"pip install 'boto3-stubs[lexv2-runtime]' boto3","lang":"bash","label":"Install via boto3-stubs extra"}],"dependencies":[{"reason":"Runtime dependency required for the type stubs to be functional. This package only provides types, not the AWS SDK itself.","package":"boto3"}],"imports":[{"note":"For explicit type annotations of the boto3 LexRuntimeV2 client.","symbol":"LexRuntimeV2Client","correct":"from mypy_boto3_lexv2_runtime.client import LexRuntimeV2Client"},{"note":"For explicit type annotations of the request dictionary for `recognize_text`.","symbol":"RecognizeTextRequestTypeDef","correct":"from mypy_boto3_lexv2_runtime.type_defs import RecognizeTextRequestTypeDef"},{"note":"For explicit type annotations of the response dictionary from `recognize_text`.","symbol":"RecognizeTextResponseTypeDef","correct":"from mypy_boto3_lexv2_runtime.type_defs import RecognizeTextResponseTypeDef"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING, cast\nimport os\n\nif TYPE_CHECKING:\n    from mypy_boto3_lexv2_runtime.client import LexRuntimeV2Client\n    from mypy_boto3_lexv2_runtime.type_defs import RecognizeTextRequestTypeDef, RecognizeTextResponseTypeDef\n\n# Instantiate boto3 client (type-checked by mypy-boto3-lexv2-runtime)\n# Credentials handled automatically by boto3, e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY env vars\n# or IAM roles.\nclient = boto3.client(\"lexv2-runtime\")\nif TYPE_CHECKING:\n    client = cast(LexRuntimeV2Client, client)\n\n# Example Lex V2 Runtime operation: recognize_text\n# Replace with your actual bot_id, bot_alias_id, locale_id\nbot_id = os.environ.get('LEX_BOT_ID', 'YOUR_BOT_ID')\nbot_alias_id = os.environ.get('LEX_BOT_ALIAS_ID', 'YOUR_BOT_ALIAS_ID')\nlocale_id = os.environ.get('LEX_LOCALE_ID', 'en_US')\nsession_id = 'test_session_id_123'\n\nrequest_params: RecognizeTextRequestTypeDef = {\n    'botId': bot_id,\n    'botAliasId': bot_alias_id,\n    'localeId': locale_id,\n    'sessionId': session_id,\n    'text': 'Hello, I need to book a flight.'\n}\n\ntry:\n    response: RecognizeTextResponseTypeDef = client.recognize_text(**request_params)\n    print(\"Lex V2 Response:\", response)\n    if response.get('messages'):\n        print(\"Bot message:\", response['messages'][0]['content'])\nexcept Exception as e:\n    print(f\"Error calling Lex V2: {e}\")\n\n# To run mypy: mypy your_script_name.py","lang":"python","description":"This quickstart demonstrates how to initialize a `boto3` LexRuntimeV2 client and perform a `recognize_text` operation with explicit type annotations provided by `mypy-boto3-lexv2-runtime`. It includes `TYPE_CHECKING` guards for runtime performance and `mypy` compatibility, as well as placeholders for necessary AWS LexV2 bot parameters."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher.","message":"Python 3.8 support has been removed. `mypy-boto3-builder` versions 8.12.0 and later (which generated `mypy-boto3-lexv2-runtime` 1.42.3) require Python 3.9 or newer.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.12.0, mypy-boto3-lexv2-runtime >= 1.42.3"},{"fix":"Update your explicit type annotations to match the new `TypeDef` naming conventions if you were affected by these changes. Consult the `mypy_boto3` documentation for the correct TypeDef names.","message":"Breaking changes to `TypeDef` naming conventions occurred in `mypy-boto3-builder` 8.9.0. Specifically, argument TypeDefs may have shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and `Extra` postfixes moved to the end.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.9.0 (affecting generated stubs for mypy-boto3-lexv2-runtime versions generated by this builder version)"},{"fix":"Ensure `boto3` is installed in your environment: `pip install boto3`.","message":"These packages provide *only* type stubs. For your Python code to run and interact with AWS services, you must also install the `boto3` library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Add explicit type hints, e.g., `from mypy_boto3_lexv2_runtime.client import LexRuntimeV2Client; client: LexRuntimeV2Client = boto3.client('lexv2-runtime')` or use `cast` within `TYPE_CHECKING` blocks.","message":"For full IDE auto-completion and static analysis with `mypy`, explicit type annotations for `boto3.client()` calls are often necessary, as Python's type inference might not correctly resolve the specific client type from overloaded `boto3.client` signatures. Using `if TYPE_CHECKING:` with `cast` is a recommended pattern.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When troubleshooting or upgrading, refer to the `mypy-boto3` documentation for the specific `boto3` version compatibility of each stub package.","message":"The version of `mypy-boto3-lexv2-runtime` (e.g., 1.42.3) is typically synchronized with the version of `boto3` it provides types for, not with the `mypy-boto3-builder` version that generated it. This can sometimes cause confusion when correlating releases.","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"}