mypy-boto3-cloudsearch Type Annotations
mypy-boto3-cloudsearch provides comprehensive type annotations for the `boto3` AWS CloudSearch service, enabling static type checking for improved code quality and developer experience. It is automatically generated with `mypy-boto3-builder` and is compatible with various IDEs and type checkers like `mypy` and `pyright`. Currently at version 1.42.3, its release cycle is frequent, aligning with updates to the underlying `boto3` library.
Warnings
- breaking As of mypy-boto3-builder 8.12.0 (which generates this package), Python 3.8 is no longer supported. Ensure your project uses Python 3.9 or newer.
- breaking mypy-boto3-builder 8.9.0 introduced naming convention changes for TypeDefs (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). While not specific to CloudSearch in the release notes, similar changes may affect other services' TypeDefs, potentially requiring updates to explicit type hints.
- gotcha This package only provides type annotations. For your code to run, the `boto3` library must also be installed in your environment.
- gotcha To prevent type stub packages from becoming runtime dependencies, especially in production environments, it is recommended to wrap `mypy-boto3-cloudsearch` imports within a `if TYPE_CHECKING:` block.
Install
-
pip install mypy-boto3-cloudsearch boto3
Imports
- CloudSearchClient
from mypy_boto3_cloudsearch import CloudSearchClient
- OptionStatusTypeDef
from mypy_boto3_cloudsearch.type_defs import OptionStatusTypeDef
- AlgorithmicStemmingType
from mypy_boto3_cloudsearch.literals import AlgorithmicStemmingType
Quickstart
import boto3
from typing import TYPE_CHECKING
# Only import type stubs during type checking to avoid runtime dependency
if TYPE_CHECKING:
from mypy_boto3_cloudsearch import CloudSearchClient
from mypy_boto3_cloudsearch.type_defs import DomainStatusTypeDef
def list_cloudsearch_domains(region_name: str = 'us-east-1') -> None:
# boto3 client is untyped by default without explicit type hints or stubs
client = boto3.client('cloudsearch', region_name=region_name)
# With mypy-boto3-cloudsearch, this client will be type-checked
if TYPE_CHECKING:
typed_client: CloudSearchClient = client
response: DomainStatusTypeDef = typed_client.describe_domains()
print(f"CloudSearch Domains: {response.get('DomainStatusList')}")
else:
# Runtime execution path
response = client.describe_domains()
print(f"CloudSearch Domains: {response.get('DomainStatusList')}")
# Example usage (will only execute at runtime if TYPE_CHECKING is False)
# For full functionality, you'll need AWS credentials configured.
# list_cloudsearch_domains()