Type Annotations for boto3 LexModelsV2
mypy-boto3-lexv2-models provides comprehensive type annotations for the `boto3` LexModelsV2 service. This package, currently at version 1.42.65, is generated using `mypy-boto3-builder 8.12.0` and aims to enhance static type checking and IDE auto-completion for `boto3` users. It follows an active release cadence, typically updating in sync with `boto3` and `botocore` releases to ensure up-to-date type definitions.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder 8.12.0`, which generates this package. Ensure your environment uses Python 3.9 or newer.
- breaking Some generated `TypeDef` names were shortened in `mypy-boto3-builder 8.9.0`. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`.
- gotcha This package provides only type annotations and does not include the actual `boto3` runtime library. `boto3` must be installed separately for your application to function at runtime.
- gotcha For Pylint compatibility and to avoid runtime dependencies on stub packages, it is recommended to conditionally import type hints using `if TYPE_CHECKING: ... else: ...` blocks.
Install
-
pip install mypy-boto3-lexv2-models boto3
Imports
- LexModelsV2Client
from mypy_boto3_lexv2_models import LexModelsV2Client
- LexModelsV2Client
from mypy_boto3_lexv2_models.client import LexModelsV2Client
- Paginator
from mypy_boto3_lexv2_models.paginator import ListBotsPaginator
- Waiter
from mypy_boto3_lexv2_models.waiter import BotLocaleBuiltWaiter
- TypedDict
from mypy_boto3_lexv2_models.type_defs import BotSummaryTypeDef
- Literal
from mypy_boto3_lexv2_models.literals import BotStatusType
Quickstart
import boto3
from typing import TYPE_CHECKING
import os
if TYPE_CHECKING:
from mypy_boto3_lexv2_models import LexModelsV2Client
from mypy_boto3_lexv2_models.type_defs import BotSummaryTypeDef
def get_lexv2_client() -> 'LexModelsV2Client':
"""Returns a type-hinted LexModelsV2 client."""
# Ensure AWS credentials are set up (e.g., via environment variables or ~/.aws/credentials)
# Using os.environ.get for demonstration purposes in a runnable quickstart.
# In a real application, boto3 will find credentials automatically.
if not os.environ.get('AWS_ACCESS_KEY_ID'):
print("Warning: AWS_ACCESS_KEY_ID not set. This example may fail without credentials.")
return boto3.client("lexv2")
def list_all_lex_bots():
client = get_lexv2_client()
print("Listing Lex V2 bots...")
try:
response = client.list_bots(sortBy={
'attribute': 'BotName',
'order': 'Ascending'
})
bots: list['BotSummaryTypeDef'] = response['botSummaries']
if bots:
for bot in bots:
print(f" Bot Name: {bot['botName']}, Status: {bot['botStatus']}")
else:
print(" No Lex V2 bots found.")
except Exception as e:
print(f"Error listing bots: {e}")
if __name__ == "__main__":
list_all_lex_bots()