mypy-boto3-backup-gateway

1.42.58 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `BackupGatewayClient` with type hints and use a basic operation like `list_gateways`. The `mypy-boto3-backup-gateway` package provides the necessary type definitions for the client and its responses, enabling static type checking with tools like MyPy.

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']}")

view raw JSON →