mypy-boto3-lex-models Type Stubs for LexModelBuildingService

1.42.3 · active · verified Sat Apr 11

mypy-boto3-lex-models provides type annotations for the boto3 LexModelBuildingService, ensuring compatibility with static type checkers like mypy and IDEs such as VSCode and PyCharm. It is generated by the `mypy-boto3-builder` project and is updated frequently to align with new `boto3` releases. This library helps in catching potential bugs, improving code completion, and enhancing the overall developer experience when interacting with the AWS Lex Model Building service.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-lex-models` to add type annotations to your boto3 client for the Lex Model Building Service. It shows importing the client type and a common response `TypeDef`, then using it to list Lex V1 bots with improved type checking and IDE support. The `TYPE_CHECKING` block ensures type imports are only active during static analysis, avoiding runtime dependencies.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_lex_models import LexModelBuildingServiceClient
    from mypy_boto3_lex_models.type_defs import GetBotVersionsResponseTypeDef

def list_lex_bots_typed() -> 'GetBotVersionsResponseTypeDef':
    """Lists Lex V1 bots with type annotations."""
    # Type checker/IDE will infer client type, but explicit annotation is good practice
    client: LexModelBuildingServiceClient = boto3.client("lex-models")
    response = client.get_bot_versions()
    print(f"Found {len(response.get('bots', []))} Lex V1 bots.")
    for bot in response.get('bots', []):
        print(f"  - {bot.get('name')} (Version: {bot.get('version')})")
    return response

if __name__ == "__main__":
    # Ensure AWS credentials (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION)
    # are configured in your environment or ~/.aws/credentials and ~/.aws/config
    list_lex_bots_typed()

view raw JSON →