mypy-boto3-amplify Type Stubs for AWS Amplify

1.42.3 · active · verified Sat Apr 11

mypy-boto3-amplify provides static type annotations for the AWS SDK for Python (boto3) specifically for the Amplify service. It helps improve code quality, enables better IDE autocompletion, and catches potential type-related errors before runtime. Currently at version 1.42.3, its releases are closely tied to boto3 updates, ensuring up-to-date type information generated by the mypy-boto3-builder.

Warnings

Install

Imports

Quickstart

This example demonstrates how to obtain a type-hinted Amplify client using `boto3` and leverage the `mypy-boto3-amplify` stubs for static analysis. It includes a `TYPE_CHECKING` guard for conditional imports, ensuring the stubs are only used during type checking and not as a runtime dependency. The `get_amplify_apps` function is fully type-hinted, including the client and the return value based on `ListAppsOutputTypeDef`.

import boto3
from typing import TYPE_CHECKING, List
import os

if TYPE_CHECKING:
    from mypy_boto3_amplify.client import AmplifyClient
    from mypy_boto3_amplify.type_defs import AppOutputTypeDef, ListAppsOutputTypeDef

def get_amplify_apps(client: 'AmplifyClient') -> List['AppOutputTypeDef']:
    """Lists Amplify applications with type hints."""
    response: 'ListAppsOutputTypeDef' = client.list_apps()
    return response.get('apps', [])

# Example usage
# Ensure AWS credentials are set up (e.g., via environment variables or ~/.aws/credentials)
# For a runnable example, we'll mock client creation

if os.environ.get('AWS_ACCESS_KEY_ID'): # Check if credentials exist for a real client
    amplify_client: 'AmplifyClient' = boto3.client('amplify')
    apps = get_amplify_apps(amplify_client)
    print(f"Found {len(apps)} Amplify applications.")
    for app in apps:
        print(f"  - App ID: {app['appId']}, Name: {app['name']}")
else:
    print("AWS credentials not found. Skipping live client example. Define AWS_ACCESS_KEY_ID to run.")

# Without type checking (runtime code)
amplify_client_untyped = boto3.client('amplify')
# This client would also work, but without static type validation.

view raw JSON →