mypy-boto3-amplify Type Stubs for AWS Amplify
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
- breaking Python 3.8 support has been removed across all `mypy-boto3-*` packages. Projects using these stubs must target Python 3.9 or higher.
- breaking TypeDef naming conventions have changed. For packed method arguments, `RequestRequestTypeDef` is shortened to `RequestTypeDef`. Conflicting `Extra` postfixes are moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`).
- deprecated The `sms-voice` service stubs have been removed as the service is no longer supported by AWS. Use `pinpoint-sms-voice` instead.
- gotcha These packages are PEP 561-compliant stub-only packages. They provide type information for `boto3` but do not contain any runtime code themselves. `mypy` and other type checkers automatically discover them if installed.
- gotcha When using `TYPE_CHECKING` guards for conditional imports, `pylint` may complain about undefined variables. To resolve this, conditionally set the imported types to `object` in the non-`TYPE_CHECKING` branch.
- gotcha While type checkers can often infer types, explicit type annotations for `boto3.client()`, `session.client()`, `client.get_waiter()`, and `client.get_paginator()` calls are highly recommended for optimal IDE autocompletion and type validation.
Install
-
pip install mypy-boto3-amplify -
pip install 'boto3-stubs[amplify]'
Imports
- AmplifyClient
from mypy_boto3_amplify.client import AmplifyClient
- AmplifyServiceName
from mypy_boto3_amplify.literals import AmplifyServiceName
- ListAppsOutputTypeDef
from mypy_boto3_amplify.type_defs import ListAppsOutputTypeDef
- TYPE_CHECKING
from typing import TYPE_CHECKING
Quickstart
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.