mypy-boto3-es: AWS Elasticsearch Service Type Stubs
mypy-boto3-es provides type annotations for the AWS ElasticsearchService (now OpenSearch Service) Boto3 client, ensuring type safety and improved IDE experience for Python developers. It is part of the `mypy-boto3` ecosystem, currently at version 1.42.81, which aligns with the `boto3` version it provides stubs for. The library is actively maintained with frequent releases, driven by the `mypy-boto3-builder` project.
Warnings
- breaking Python 3.8 support was removed from `mypy-boto3-builder` in version 8.12.0. This means `mypy-boto3-es` versions generated by this builder (typically `1.42.x` and later) require Python 3.9 or newer.
- breaking Type definition (TypeDef) naming conventions changed in `mypy-boto3-builder` 8.9.0. Specifically, redundant 'Request' suffixes were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`). While the specific `es` service might not have these exact TypeDefs, users relying on explicit `mypy-boto3` TypeDef names across services may need to update their code.
- gotcha The `mypy-boto3-es` package provides *only* type stubs. You must install `boto3` separately for your code to actually run and interact with AWS services. Similarly, `mypy` is required to perform static type checking.
- gotcha The version of `mypy-boto3-es` typically corresponds to the `boto3` version it provides stubs for. If you upgrade `boto3` but do not update `mypy-boto3-es` to a matching or compatible version, you may encounter incorrect or missing type hints.
Install
-
pip install mypy-boto3-es -
pip install boto3 mypy
Imports
- ElasticsearchClient
from mypy_boto3_es.client import ElasticsearchClient
- Service-specific TypeDefs
from mypy_boto3_es.type_defs import DomainConfigTypeDef
Quickstart
import boto3
from mypy_boto3_es.client import ElasticsearchClient
# Instantiate the boto3 client with type hinting
es_client: ElasticsearchClient = boto3.client("es")
try:
# Example usage: list domain names
response = es_client.list_domain_names()
for domain in response.get('DomainNames', []):
print(f"Found domain: {domain['DomainName']}")
except Exception as e:
print(f"An error occurred: {e}")