mypy-boto3-backup-gateway
mypy-boto3-backup-gateway provides high-quality type annotations for the boto3 BackupGateway service, ensuring better code completion, static analysis, and error detection in development environments. It is part of the larger `mypy-boto3` ecosystem, generated by `mypy-boto3-builder`. The current version is 1.42.58, and it is frequently updated to align with `boto3` releases and schema changes.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. All `mypy-boto3` packages, including `mypy-boto3-backup-gateway`, now require Python 3.9 or newer.
- breaking The `mypy-boto3` ecosystem migrated to PEP 561-compliant packaging in `mypy-boto3-builder` version 8.12.0. This might require updating older type checker configurations or virtual environments to correctly discover stubs, though it generally improves compatibility with modern tooling.
- breaking In `mypy-boto3-builder` version 8.9.0, certain TypeDef names were refactored for clarity and consistency. Specifically, TypeDefs for packed method arguments use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and conflicting `Extra` postfixes were moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).
- gotcha While `mypy-boto3` strives for implicit type inference, some IDEs (like VSCode with older Python extensions or PyCharm) may still benefit from explicit type annotations for `boto3.client` and `session.client` calls to provide optimal auto-completion and type checking. For example, `client: BackupGatewayClient = session.client('backup-gateway')`.
Install
-
pip install mypy-boto3-backup-gateway
Imports
- BackupGatewayClient
from mypy_boto3_backup_gateway.client import BackupGatewayClient
- ListGatewaysOutputTypeDef
from mypy_boto3_backup_gateway.type_defs import ListGatewaysOutputTypeDef
Quickstart
import boto3
from boto3.session import Session
from mypy_boto3_backup_gateway.client import BackupGatewayClient
from mypy_boto3_backup_gateway.type_defs import ListGatewaysOutputTypeDef
def get_backup_gateway_client() -> BackupGatewayClient:
"""Initializes and returns a type-hinted BackupGateway client."""
# A real application would configure AWS credentials via environment variables or ~/.aws/credentials
session = Session(region_name='us-east-1')
client: BackupGatewayClient = session.client('backup-gateway')
return client
def list_all_gateways() -> ListGatewaysOutputTypeDef:
"""Lists all Backup Gateways and returns the typed response."""
client = get_backup_gateway_client()
response: ListGatewaysOutputTypeDef = client.list_gateways()
print(f"Found {len(response['Gateways'])} gateways.")
return response
if __name__ == '__main__':
gateways_data = list_all_gateways()
# Mypy will now correctly infer types for gateways_data, e.g., gateways_data['Gateways']
# without needing runtime checks.
for gateway in gateways_data.get('Gateways', []):
print(f"Gateway ARN: {gateway['GatewayArn']}, Name: {gateway['GatewayDisplayName']}")