mypy-boto3-comprehend type annotations
mypy-boto3-comprehend provides type annotations for the `boto3` Comprehend service, compatible with `mypy`, `pyright`, VSCode, PyCharm, and other tools. It is part of the `mypy-boto3` ecosystem, with its types automatically generated by `mypy-boto3-builder`. The library ensures that all public classes and methods of the `boto3` Comprehend service have valid, up-to-date type annotations extracted from `botocore` schemas, including documentation links. The project follows a frequent release cadence, often aligning with `boto3` updates.
Warnings
- breaking Python 3.8 support has been removed across all `mypy-boto3-*` packages, including `mypy-boto3-comprehend`. Projects must use Python 3.9 or newer.
- breaking All `mypy-boto3-*` packages, including this one, migrated to PEP 561 compliant distribution. While this is a standard, older toolchains or custom stub paths might require adjustments.
- gotcha This package provides *only* type annotations. The `boto3` library itself must be installed in your environment for the code to run. Installing `mypy-boto3-comprehend` does not install `boto3`.
- gotcha PyCharm users may experience slow performance or high CPU usage with `boto3-stubs` packages (which `mypy-boto3-comprehend` is part of, or can be installed as an extra). This is due to PyCharm's internal type checker handling of Literal overloads.
Install
-
pip install mypy-boto3-comprehend -
pip install 'boto3-stubs[comprehend]'
Imports
- ComprehendClient
from mypy_boto3_comprehend import ComprehendClient
Quickstart
import boto3
from mypy_boto3_comprehend import ComprehendClient
from typing import TYPE_CHECKING
# Boto3 client without explicit typing (type checkers may infer correctly)
client = boto3.client("comprehend")
client.detect_dominant_language(Text="Hello, this is a test.")
# Explicit typing for better IDE support and type checking
if TYPE_CHECKING:
# In a real scenario, use actual AWS credentials
# or ensure they are configured via environment variables or ~/.aws/credentials
session = boto3.Session(region_name='us-east-1') # Or any appropriate region
typed_client: ComprehendClient = session.client("comprehend")
response = typed_client.detect_dominant_language(Text="Hola, esto es una prueba.")
print(response['Languages'][0]['LanguageCode'])