Type Annotations for Boto3 SWF

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This example demonstrates how to initialize a type-hinted SWF client using `boto3.client` and then use it with `mypy-boto3-swf`'s stubs for static analysis. It shows how to import and apply `SWFClient` for the client object and `ListDomainsResponseTypeDef` for API call responses, ensuring type safety for your `boto3` interactions.

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

view raw JSON →