mypy-boto3-observabilityadmin type stubs
mypy-boto3-observabilityadmin provides type annotations for the boto3 CloudWatchObservabilityAdminService, enabling static type checking with tools like MyPy. It's part of the `mypy-boto3` ecosystem, which generates stubs for all AWS services supported by `boto3`. The current version is 1.42.88, with releases closely tracking `boto3` and `botocore` updates, often multiple times a month.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-observabilityadmin` 1.42.88+), Python 3.8 is no longer supported. Projects using these stubs must run on Python 3.9 or newer.
- gotcha These packages provide only type stubs. You must install the actual `boto3` library separately for your code to run at runtime. For optimal type checking, ensure your `boto3` version is compatible with the stub version.
- gotcha For the most accurate type checking, the `mypy-boto3-*` stub package version should ideally align with your installed `boto3` runtime version. Significant mismatches can lead to incorrect type hints or `mypy` errors.
- breaking In `mypy-boto3-builder` version 8.9.0, there were changes to TypeDef naming conventions (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`). If you directly import and use `TypeDef` classes by their exact names, this could cause import errors or type mismatches.
Install
-
pip install mypy-boto3-observabilityadmin boto3
Imports
- ObservabilityAdminClient
from mypy_boto3_observabilityadmin import ObservabilityAdminClient
- ListServiceLevelObjectivesOutputTypeDef
from mypy_boto3_observabilityadmin.type_defs import ListServiceLevelObjectivesOutputTypeDef
Quickstart
import boto3
from mypy_boto3_observabilityadmin import ObservabilityAdminClient
from mypy_boto3_observabilityadmin.type_defs import ListServiceLevelObjectivesOutputTypeDef
def get_observability_admin_client() -> ObservabilityAdminClient:
"""
Returns a typed CloudWatchObservabilityAdminService client.
Your IDE will provide type hints for methods and arguments on 'client'.
"""
client: ObservabilityAdminClient = boto3.client("observabilityadmin")
return client
if __name__ == "__main__":
client = get_observability_admin_client()
print(f"Successfully created a typed ObservabilityAdminClient: {type(client)}")
# Example of a typed response (requires AWS credentials and permissions)
try:
# MyPy will ensure 'response' conforms to ListServiceLevelObjectivesOutputTypeDef
response: ListServiceLevelObjectivesOutputTypeDef = client.list_service_level_objectives()
slo_count = len(response.get('ServiceLevelObjectives', []))
print(f"Successfully called list_service_level_objectives. Found {slo_count} SLOs.")
except client.exceptions.ClientError as e:
print(f"Could not list Service Level Objectives (expected if no permissions or resources): {e}")
print("\nThis demonstrates how `mypy-boto3-observabilityadmin` provides type hints for your boto3 client interactions.")