Type annotations for boto3 WellArchitected
This library provides static type annotations for the AWS Well-Architected service, enabling `mypy` to perform static type checking on `boto3` code. It ensures type safety and enhances developer experience with improved autocompletion. The current version is 1.42.3, and it follows the `mypy-boto3-builder` release cadence, which is typically frequent due to `boto3` updates.
Warnings
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and subsequent `mypy-boto3` packages. Users on Python 3.8 will need to upgrade to Python 3.9 or higher.
- breaking In `mypy-boto3-builder` version 8.9.0, TypeDef names for packed method arguments were shortened, and conflicting `Extra` postfixes were moved. If you have explicitly imported or referenced generated `TypeDef` names, these may have changed.
- gotcha The `mypy-boto3` ecosystem migrated to PEP 561 packages in `mypy-boto3-builder` 8.12.0. While beneficial for type checkers, it might cause unexpected behavior with older `pip` versions or custom build systems that do not correctly handle PEP 561 stub distribution.
- gotcha For optimal type checking and compatibility, the version of `mypy-boto3-wellarchitected` should ideally align with the version of `boto3` you are using. Mismatched versions can lead to incorrect type hints or missing attributes, especially after significant `boto3` updates.
Install
-
pip install mypy-boto3-wellarchitected -
pip install 'boto3-stubs[wellarchitected]'
Imports
- WellArchitectedClient
from mypy_boto3_wellarchitected.client import WellArchitectedClient
- WellArchitectedServiceName
from mypy_boto3_wellarchitected.type_defs import CreateWorkloadInputRequestTypeDef
Quickstart
import os
import boto3
from mypy_boto3_wellarchitected.client import WellArchitectedClient
def get_wellarchitected_client() -> WellArchitectedClient:
"""Initializes and returns a WellArchitectedClient with type annotations."""
session = boto3.Session(
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
client: WellArchitectedClient = session.client("wellarchitected")
return client
# Example usage (will require valid AWS credentials for actual execution)
if __name__ == "__main__":
try:
wa_client = get_wellarchitected_client()
# This call will typically fail without proper credentials and permissions
# but demonstrates type-hinted client usage.
response = wa_client.list_workloads(
MaxResults=10
)
print("Successfully initialized WellArchitected client (response may be empty/error without valid creds).")
# print(response.get('WorkloadSummaries'))
except Exception as e:
print(f"An error occurred: {e}")