mypy-boto3-chatbot Type Annotations
mypy-boto3-chatbot provides comprehensive type annotations for the `boto3` AWS Chatbot service. Generated by `mypy-boto3-builder` (currently version 8.12.0), this library enables static type checking with tools like `mypy` and `pyright`, offering improved autocompletion and early error detection in IDEs like VSCode and PyCharm. It is updated frequently to synchronize with the latest `boto3` service definitions (current `chatbot` version 1.42.3).
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0, support for Python 3.8 has been removed for all generated stub packages, including `mypy-boto3-chatbot`. The library now requires Python >=3.9.
- breaking Version 8.9.0 of `mypy-boto3-builder` introduced breaking changes to `TypeDef` naming conventions. Some TypeDefs (e.g., method argument types) now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`).
- gotcha When using `mypy-boto3-chatbot` as a standalone package or the `types-boto3-lite` variants, explicit type annotations are necessary for `boto3.client()` and `session.client()` calls to leverage full static analysis and IDE autocompletion. The full `types-boto3` package provides function overloads for automatic type inference.
- gotcha PyCharm users might experience performance slowdowns when working with `Literal` overloads in `mypy-boto3` packages. As a workaround, the `types-boto3-lite` versions are often recommended, which typically necessitate explicit type annotations.
Install
-
pip install mypy-boto3-chatbot -
pip install 'types-boto3[chatbot]'
Imports
- ChatbotClient
from mypy_boto3_chatbot.client import ChatbotClient
- AccountPreferencesTypeDef
from mypy_boto3_chatbot.type_defs import AccountPreferencesTypeDef
- CustomActionAttachmentCriteriaOperatorType
from mypy_boto3_chatbot.literals import CustomActionAttachmentCriteriaOperatorType
- ListMicrosoftTeamsChannelConfigurationsPaginator
from mypy_boto3_chatbot.paginator import ListMicrosoftTeamsChannelConfigurationsPaginator
Quickstart
import boto3
from typing import TYPE_CHECKING, Dict, Any
# Ensure boto3 is installed for runtime functionality
# pip install boto3
if TYPE_CHECKING:
from mypy_boto3_chatbot.client import ChatbotClient
from mypy_boto3_chatbot.type_defs import DescribeChatbotSourcesResponseTypeDef
def get_chatbot_sources(aws_region: str = "us-east-1") -> Dict[str, Any]:
"""
Retrieves and type-checks AWS Chatbot sources using mypy-boto3-chatbot stubs.
"""
# boto3.client returns an untyped client by default
client: ChatbotClient = boto3.client("chatbot", region_name=aws_region)
# The response is now type-checked, providing autocompletion and validation
response: DescribeChatbotSourcesResponseTypeDef = client.describe_chatbot_sources()
print(f"Chatbot sources response: {response}")
return response
if __name__ == "__main__":
# This assumes AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
try:
sources = get_chatbot_sources()
print(f"Successfully retrieved chatbot sources with HTTP status: {sources['ResponseMetadata']['HTTPStatusCode']}")
except Exception as e:
print(f"An error occurred while fetching chatbot sources: {e}")