Type Annotations for Boto3 PrometheusService (AMP)
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
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generates these stubs), Python 3.8 is no longer supported. Projects using Python 3.8 must upgrade to Python 3.9 or newer to use the latest `mypy-boto3` stubs. The packages also migrated to PEP 561 compliance.
- breaking Version 8.9.0 of `mypy-boto3-builder` introduced breaking changes to `TypeDef` naming conventions. `TypeDefs` for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes are moved to the end. This may require updating explicit type annotations in existing code.
- gotcha PyCharm users might experience slow performance and high CPU usage, especially with `Literal` overloads, due to a known PyCharm issue (PY-40997). It is recommended to either use `boto3-stubs-lite` (if explicit type annotations are acceptable) or to disable PyCharm's built-in type checker and rely on `mypy` or `pyright` for type checking.
- gotcha While `mypy-boto3-amp` provides type annotations for `boto3`'s AMP client, `boto3` itself is a separate runtime dependency and must be installed in your environment. These packages are type stubs, not the actual AWS SDK.
- deprecated The `mypy-boto3` ecosystem has seen service name changes, such as `sms-voice` being deprecated in favor of `pinpoint-sms-voice` in `mypy-boto3-builder` 8.11.0. While not directly affecting AMP, this highlights that AWS service names can change, leading to deprecations in stub packages. Always verify service names against current AWS documentation.
Install
-
pip install mypy-boto3-amp boto3 mypy -
pip install 'boto3-stubs[amp]' boto3 mypy
Imports
- PrometheusServiceClient
from mypy_boto3_amp import PrometheusServiceClient
- ListWorkspacesPaginator
from mypy_boto3_amp.paginator import ListWorkspacesPaginator
- CreateWorkspaceRequestRequestTypeDef
from mypy_boto3_amp.type_defs import CreateWorkspaceRequestRequestTypeDef
Quickstart
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