mypy-boto3-cloudsearch Type Annotations

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This example demonstrates how to initialize a `boto3` CloudSearch client and leverage the `mypy-boto3-cloudsearch` type annotations for static analysis. It includes an `if TYPE_CHECKING:` block, which is a common pattern to ensure the type stub imports do not create runtime dependencies.

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()

view raw JSON →