Type Annotations for Boto3 PrometheusService (AMP)

1.42.3 · active · verified Sat Apr 11

mypy-boto3-amp provides PEP 561 compatible type annotations for `boto3`'s PrometheusService (Amazon Managed Service for Prometheus, AMP) client. It enhances developer experience by enabling static type checking and autocompletion for `boto3` code with tools like mypy, pyright, VSCode, and PyCharm. The library is actively maintained, with frequent updates in sync with `boto3` versions, and is currently at version 1.42.3, generated with mypy-boto3-builder 8.12.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `boto3` client for Amazon Managed Service for Prometheus (AMP) with `mypy-boto3-amp` type annotations. It shows how to import and apply the `PrometheusServiceClient` type to get full type checking and autocompletion for client methods and their arguments/return values. Remember to have `boto3` and `mypy` installed in your environment.

import boto3
from mypy_boto3_amp import PrometheusServiceClient
from mypy_boto3_amp.type_defs import CreateWorkspaceRequestRequestTypeDef
import os

# Boto3 client without type annotations
# untyped_client = boto3.client("amp")
# response = untyped_client.list_workspaces()

# Boto3 client with type annotations
client: PrometheusServiceClient = boto3.client("amp")

# Example usage with type-hinted client
print("Listing AMP workspaces...")
try:
    # Using a method that typically exists for AMP clients
    response = client.list_workspaces()
    print(f"Found {len(response.get('workspaces', []))} workspaces.")
    # Example of creating a workspace with typed dictionary (requires a unique name)
    # create_params: CreateWorkspaceRequestRequestTypeDef = {
    #     "alias": f"my-typed-workspace-{os.environ.get('UNIQUE_ID', 'test')}"
    # }
    # create_response = client.create_workspace(**create_params)
    # print(f"Created workspace with ID: {create_response['workspaceId']}")
except client.exceptions.ResourceNotFoundException:
    print("No AMP workspaces found or permissions issue.")
except Exception as e:
    print(f"An error occurred: {e}")

# Run mypy to check types:
# mypy your_script_name.py

view raw JSON →