Type Annotations for Boto3 SWF
mypy-boto3-swf provides a set of type annotations (stubs) for the boto3 SWF (Simple Workflow Service) client. It enables static type checking with tools like MyPy for `boto3` interactions, enhancing code reliability and developer experience. The library is actively maintained, with new versions released frequently in sync with `boto3` updates and `mypy-boto3-builder` developments.
Warnings
- breaking Python 3.8 support has been officially removed starting with `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-swf` 1.42.3). Projects using these stubs now require Python 3.9 or higher.
- breaking All `mypy-boto3` packages, including `mypy-boto3-swf`, migrated to PEP 561 compliant distributions with `mypy-boto3-builder` 8.12.0. This might affect how type checkers locate and use stubs in specific build or environment configurations.
- gotcha `mypy-boto3-swf` provides *only* type annotations (stubs). It does not include the `boto3` runtime itself. For your code to run, you must install `boto3` as well.
- breaking Older projects using the monolithic `mypy-boto3` package for all services should migrate to service-specific stub packages like `mypy-boto3-swf`. The builder changed to separate products in 8.9.0.
Install
-
pip install boto3 mypy-boto3-swf
Imports
- SWFClient
from mypy_boto3_swf.client import SWFClient
- ListDomainsResponseTypeDef
from mypy_boto3_swf.type_defs import ListDomainsResponseTypeDef
- boto3.client('swf')
import boto3; client: SWFClient = boto3.client('swf')
Quickstart
import boto3
from mypy_boto3_swf.client import SWFClient
from mypy_boto3_swf.type_defs import ListDomainsResponseTypeDef, DomainInfoTypeDef
# Create a typed SWF client
# Note: boto3 itself needs to be installed, mypy-boto3-swf only provides type stubs.
client: SWFClient = boto3.client("swf")
try:
# List registered domains and type-hint the response
response: ListDomainsResponseTypeDef = client.list_domains(
registrationStatus="REGISTERED",
maximumPageSize=5
)
print(f"Registered SWF Domains: {response.get('domainInfos', [])}")
# Example of processing specific domain info with a TypeDef
def process_domain_info(domain_info: DomainInfoTypeDef) -> None:
print(f"Domain Name: {domain_info['name']}, Status: {domain_info['status']}")
if 'domainInfos' in response and response['domainInfos']:
process_domain_info(response['domainInfos'][0])
except Exception as e:
print(f"Error listing domains: {e}")