mypy-boto3-opensearch type stubs

1.42.81 · active · verified Sat Apr 11

mypy-boto3-opensearch provides static type annotations for the boto3 OpenSearchService client and its data structures. It's part of the `mypy-boto3` project, which programmatically generates up-to-date type stubs for all boto3 services. The library's releases closely follow boto3's release cadence, ensuring compatibility with the latest AWS SDK features. The current version is 1.42.81.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `mypy-boto3-opensearch` stubs with a `boto3` OpenSearchService client. It initializes a type-hinted client, calls `list_domain_names`, and prints the results. Remember to have `boto3` installed and AWS credentials configured. The example uses environment variables for credentials, but `boto3` supports various credential providers. Run `mypy your_script.py` to see type checking in action.

import boto3
from mypy_boto3_opensearch.client import OpenSearchServiceClient
from mypy_boto3_opensearch.type_defs import ListDomainNamesResponseTypeDef
import os

# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# For demonstration, using environment variables if available
aws_access_key_id = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY')
aws_secret_access_key = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_KEY')
aws_session_token = os.environ.get('AWS_SESSION_TOKEN', None)

# Initialize the boto3 client for OpenSearchService, type-hinted for mypy-boto3 stubs
client: OpenSearchServiceClient = boto3.client(
    "opensearch",
    region_name="us-east-1",
    aws_access_key_id=aws_access_key_id,
    aws_secret_access_key=aws_secret_access_key,
    aws_session_token=aws_session_token
)

try:
    # Use the client; type-checking will now be active when running `mypy`
    response: ListDomainNamesResponseTypeDef = client.list_domain_names()
    print("OpenSearch Domains:")
    if response.get("DomainNames"):
        for domain in response["DomainNames"]:
            print(f"- {domain.get('DomainName')}")
    else:
        print(
            "No domains found in us-east-1 region or credentials not configured correctly."
        )
except Exception as e:
    print(f"Error listing domains: {e}")

# To verify type checking, save this code as `your_script.py` and run `mypy your_script.py` in your terminal.

view raw JSON →