Type Annotations for boto3 LexModelsV2

1.42.65 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This example demonstrates how to obtain a type-hinted `LexModelsV2Client` using `boto3` and then use it to list Lex V2 bots. It leverages `TYPE_CHECKING` for conditional import of the stub types, ensuring they are only used during static analysis.

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()

view raw JSON →