Type Annotations for boto3 AWS ManagedGrafana
mypy-boto3-grafana provides static type annotations for the boto3 AWS ManagedGrafana service. It helps developers leverage mypy and IDEs for better code completion and error checking when working with boto3. The package is generated by `mypy-boto3-builder` and is updated frequently to align with new boto3 releases and AWS service updates, currently at version 1.42.51.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0, support for Python 3.8 was removed. Projects using older Python versions must pin to an older `mypy-boto3-grafana` version generated by a builder prior to 8.12.0 or upgrade their Python version.
- breaking Version 8.9.0 of `mypy-boto3-builder` introduced breaking changes in TypeDef naming conventions, potentially causing import errors or type mismatches if you were explicitly referencing generated TypedDicts with the old naming scheme.
- gotcha While some IDEs (like PyCharm) and `mypy` can infer types for `boto3.client` calls, explicit type annotations (e.g., `client: ManagedGrafanaClient = boto3.client("grafana")`) are often recommended for optimal autocompletion and comprehensive type checking, especially when using VSCode or the `boto3-stubs-lite` packages.
- gotcha Pylint may complain about undefined variables when using `typing.TYPE_CHECKING` guards. This is a known issue with Pylint's static analysis when types are only defined conditionally.
- gotcha PyCharm users might experience slow performance or high CPU usage due to how it handles `Literal` overloads. This can be particularly noticeable with comprehensive stub packages like `mypy-boto3-grafana`.
Install
-
pip install boto3 mypy-boto3-grafana
Imports
- ManagedGrafanaClient
from mypy_boto3_grafana.client import ManagedGrafanaClient
- ListWorkspacesResponseTypeDef
from mypy_boto3_grafana.type_defs import ListWorkspacesResponseTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_grafana.client import ManagedGrafanaClient
from mypy_boto3_grafana.type_defs import ListWorkspacesResponseTypeDef
def get_grafana_workspaces():
# In a real application, consider using environment variables or other secure methods for credentials
client: ManagedGrafanaClient = boto3.client("grafana")
# Example: List AWS Grafana workspaces
response: ListWorkspacesResponseTypeDef = client.list_workspaces()
for workspace in response.get("workspaces", []):
print(f"Workspace Name: {workspace.get('workspaceName')}, Status: {workspace.get('workspaceStatus')}")
if __name__ == "__main__":
get_grafana_workspaces()
# To type-check this file: mypy your_script_name.py