mypy-boto3-rum: CloudWatchRUM Type Stubs
mypy-boto3-rum provides type annotations for the `boto3` CloudWatchRUM service, enhancing static analysis with tools like Mypy and Pyright. It is part of the `mypy-boto3` family of packages, generated by `mypy-boto3-builder`. The library is actively maintained with frequent updates, aligning with `boto3` releases to ensure up-to-date type information.
Warnings
- breaking Python 3.8 support has been removed as of `mypy-boto3-builder` version 8.12.0. Ensure your project runs on Python 3.9 or newer.
- breaking The `mypy-boto3` ecosystem migrated to PEP 561 compliant packages with `mypy-boto3-builder` 8.12.0. While largely backward compatible, it changes how type checkers discover stubs. Ensure your `mypy` is up to date.
- breaking Some generated `TypeDef` names were shortened in `mypy-boto3-builder` 8.9.0 (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). If you were explicitly importing and using such type definitions, they might have changed.
- gotcha For optimal code completion and type inference in IDEs like VSCode or PyCharm, it is often recommended to use explicit type annotations for `boto3.client` and `boto3.resource` calls, even though `mypy` might infer them implicitly.
- gotcha Pylint might raise `undefined-variable` warnings when using `mypy-boto3` stubs with `TYPE_CHECKING` guards.
- gotcha PyCharm users might experience slow performance or high CPU usage due to the complexity of `boto3-stubs`'s literal overloads.
Install
-
pip install mypy-boto3-rum boto3
Imports
- CloudWatchRUMClient
from mypy_boto3_rum.client import CloudWatchRUMClient
- boto3
import boto3
Quickstart
import boto3
from typing import TYPE_CHECKING
# For explicit type hinting, especially helpful for IDEs
if TYPE_CHECKING:
from mypy_boto3_rum.client import CloudWatchRUMClient
from mypy_boto3_rum.type_defs import ListAppMonitorsResponseTypeDef
def get_rum_client() -> 'CloudWatchRUMClient':
"""Initializes and returns a typed CloudWatchRUM client."""
# Mypy will correctly infer the type of 'client' if mypy-boto3-rum is installed
client: CloudWatchRUMClient = boto3.client('rum')
return client
def list_rum_app_monitors():
client = get_rum_client()
try:
response: ListAppMonitorsResponseTypeDef = client.list_app_monitors()
print(f"Found {len(response.get('AppMonitorSummaries', []))} app monitors.")
for monitor_summary in response.get('AppMonitorSummaries', []):
print(f" - {monitor_summary.get('Name')}: {monitor_summary.get('Id')}")
except client.exceptions.ResourceNotFoundException:
print("No CloudWatch RUM app monitors found.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == '__main__':
# This assumes AWS credentials are configured (e.g., via ~/.aws/credentials or env vars)
# For a real application, consider explicit region and credentials
list_rum_app_monitors()