mypy-boto3-opensearchserverless Type Stubs
mypy-boto3-opensearchserverless provides type annotations for the `boto3` OpenSearchServiceServerless client, generated with `mypy-boto3-builder`. It enhances static type checking for your AWS `boto3` code. The current version is 1.42.75, with new releases frequently (typically aligning with `boto3` and `botocore` updates) due to its auto-generated nature.
Warnings
- breaking Python 3.8 is no longer supported. `mypy-boto3-builder` (which generates these stubs) removed support for Python 3.8 across all packages, migrating to PEP 561.
- breaking Type Definition names for method arguments may have changed, becoming shorter. For example, `CreateDistributionRequestRequestTypeDef` might become `CreateDistributionRequestTypeDef`.
- gotcha This package provides only type stubs. The actual `boto3` library must be installed separately for your code to run.
- gotcha While the stubs provide type hints, `mypy` itself is required to perform static type checking. Simply installing the stubs does not automatically enable type checks.
Install
-
pip install boto3 mypy mypy-boto3-opensearchserverless
Imports
- OpenSearchServiceServerlessClient
from mypy_boto3_opensearchserverless.client import OpenSearchServiceServerlessClient
- TypeDefs
from mypy_boto3_opensearchserverless.type_defs import CreateCollectionRequestTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
# Import the specific client stub for type annotation
from mypy_boto3_opensearchserverless.client import OpenSearchServiceServerlessClient
# To make mypy aware of the typed client, use TYPE_CHECKING
if TYPE_CHECKING:
client: OpenSearchServiceServerlessClient = boto3.client("opensearchserverless")
else:
client = boto3.client("opensearchserverless")
# Example usage: listing collections
try:
# This call will be type-checked based on the stub annotations
response = client.list_collections(maxResults=1)
print(f"First collection details: {response.get('collectionDetails', [])}")
except Exception as e:
print(f"Error listing collections (expected if no auth/resources configured): {e}")
# Example of using a TypeDef (e.g., for creating a collection)
# from mypy_boto3_opensearchserverless.type_defs import CreateCollectionRequestTypeDef
#
# # mypy will validate the structure of this dictionary
# collection_config: CreateCollectionRequestTypeDef = {
# "name": "my-typed-collection",
# "type": "SEARCH",
# "description": "A collection created with type-checked parameters"
# }
# print(f"Collection configuration: {collection_config}")