mypy-boto3-lex-models Type Stubs for LexModelBuildingService
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
- breaking Python 3.8 support was removed for all `mypy-boto3` packages with `mypy-boto3-builder 8.12.0` and later. Users must upgrade to Python 3.9 or newer.
- breaking Packages migrated to PEP 561. This change affects how type checkers discover and use the stubs. Ensure your type checker is configured to correctly find PEP 561 compliant packages.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder 8.9.0`. Packed method arguments use shorter names (`CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes moved (`CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).
- gotcha While standalone `mypy-boto3-lex-models` is installable, for managing multiple AWS service stubs, `pip install 'boto3-stubs[lex-models]'` (or `types-boto3[lex-models]`) is often recommended. This keeps service stubs version-locked to `boto3` and simplifies dependency management.
- gotcha PyCharm users might experience slow performance with Literal overloads. For better IDE responsiveness, especially with many services, consider installing the 'lite' version of stubs (e.g., `boto3-stubs-lite[lex-models]`).
- gotcha When using `from typing import TYPE_CHECKING` guards to conditionally import stubs for Pylint compatibility, Pylint might report 'undefined variable' errors outside the `TYPE_CHECKING` block. A common workaround is to assign `object` to the type hints in the `else` branch.
Install
-
pip install mypy-boto3-lex-models -
pip install 'boto3-stubs[lex-models]'
Imports
- LexModelBuildingServiceClient
from mypy_boto3_lex_models import LexModelBuildingServiceClient
- GetBotVersionsResponseTypeDef
from mypy_boto3_lex_models.type_defs import GetBotVersionsResponseTypeDef
Quickstart
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()