mypy-boto3-backup: Type Annotations for AWS Backup Service
mypy-boto3-backup provides static type annotations for the AWS Backup 1.42.86 service, generated with mypy-boto3-builder 8.12.0. It enhances developer experience by offering type checking and auto-completion for `boto3` clients, resources, paginators, waiters, and specific type definitions for the Backup service, compatible with `mypy`, `pyright`, VSCode, and PyCharm.
Warnings
- breaking As of `mypy-boto3-builder` 8.12.0 (which generates `mypy-boto3-backup` versions 1.42.x and later), support for Python 3.8 has been removed. Projects using these stubs must target Python 3.9 or newer.
- breaking Starting with `mypy-boto3-builder` 8.12.0, all `mypy-boto3` packages migrated to PEP 561. This change affects how type checkers (like `mypy`) discover and use type information, potentially requiring updates to `mypy` configurations or environment setups if issues arise.
- breaking Version 8.9.0 of `mypy-boto3-builder` introduced breaking changes to how TypeDef names are generated. Specifically, argument TypeDefs were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`). While the example refers to other services, this naming convention change may apply to other service-specific TypeDefs.
- gotcha If you were previously using the monolithic `mypy-boto3` package, note that `mypy-boto3-builder` 8.9.0 moved the 'legacy' `mypy-boto3` to a separate product. This means you should now install `boto3-stubs` (with service extras) or specific `mypy-boto3-service` packages like `mypy-boto3-backup`.
- gotcha When using standalone `mypy-boto3-backup` (or `boto3-stubs-lite[backup]`), explicit type annotations for `boto3.client` and `boto3.resource` calls are recommended for optimal type checking and auto-completion, as these packages may not provide overloads for `session.client`/`resource`.
Install
-
pip install mypy-boto3-backup boto3 -
pip install 'boto3-stubs[backup]' boto3
Imports
- BackupClient
from mypy_boto3_backup.client import BackupClient
- ListBackupPlansOutputTypeDef
from mypy_boto3_backup.type_defs import ListBackupPlansOutputTypeDef
- AggregationPeriodType
from mypy_boto3_backup.literals import AggregationPeriodType
Quickstart
import boto3
from typing import TYPE_CHECKING
# These imports are only for type checking and won't be bundled in production
if TYPE_CHECKING:
from mypy_boto3_backup.client import BackupClient
from mypy_boto3_backup.type_defs import ListBackupPlansOutputTypeDef
def get_backup_plans() -> ListBackupPlansOutputTypeDef:
"""Lists AWS Backup plans and returns the response."""
# Type annotation for the client for better IDE support and mypy checking
client: BackupClient = boto3.client("backup")
response = client.list_backup_plans(
MaxResults=5, # Example parameter
# Add other filters or parameters as needed
)
return response
if __name__ == "__main__":
try:
backup_plans = get_backup_plans()
print(f"Successfully retrieved {len(backup_plans.get('BackupPlansList', []))} backup plans.")
for plan in backup_plans.get('BackupPlansList', [])[:2]: # Print first 2 for brevity
print(f" - Plan ID: {plan.get('BackupPlanId')}, Name: {plan.get('BackupPlanName')}")
except Exception as e:
print(f"Error listing backup plans: {e}")