Skip to main content
Step Scribe logo

A package to write AWS Step Function state machines using python and output valid AWS states language JSON or to various visualization formats (eventually).

Installation

pip install stepscribe

Examples

Here's a simple task example that invokes an existing lambda function:

from stepscribe import Task

if __name__ == "__main__":
    get_price = Task(
                    Name="Get Current Price",
                    Next='Check Price',
                    Resource="arn:aws:states:::lambda:invoke",
                    Arguments={'Payload': {"product": "{% $states.context.Execution.Input.product %}"},
                        'FunctionName': "arn:aws:lambda:<region>:account-id:function:priceWatcher:$LATEST",
                    },
                    Assign={'currentPrice': "{% $states.result.Payload.current_price %}"}
    )
    print(get_price.to_asl_json(indent=2))               

This python code generates the following Amazon states language JSON:

{
"Get Current Price": {
  "Type": "Task",
  "QueryLanguage" : "JSONata",
  "Resource": "arn:aws:states:::lambda:invoke",
  "Next": "Check Price",
  "Arguments": {
    "Payload": {
    "product": "{% $states.context.Execution.Input.product %}"
    },
    "FunctionName": "arn:aws:lambda:<region>:account-id:function:priceWatcher:$LATEST"
  },
  "Assign": {
    "currentPrice": "{% $states.result.Payload.current_price %}"
  }
}
}

The value of StepScribe comes from leveraging python to create or compose objects and then generate the corresponding JSON. For example, what if we wanted to get the current price of a product, check if it's on sale, and check our inventory. If each of these actions is a lambda, we now need 3 tasks like above, but with different names and lambda functions, and each of these to be a branch of a parallel state.

from stepscribe import Task, Parallel

def product_task(name: str, lambda_name: str) -> Task:
    output=name.lower().replace(' ', '_').replace('get_', '')

    return Task(
                Name=name,
                Next='Check Price',
                Resource="arn:aws:states:::lambda:invoke",
                Arguments={'Payload': {"product": "{% $states.context.Execution.Input.product %}"},
                        'FunctionName': f"arn:aws:lambda:<region>:account-id:function:{lambda_name}:$LATEST",
                },
                Assign={'currentPrice': f"{{% $states.result.Payload.{output} %}}"}
    )


if __name__ == "__main__":

    tasks = [("Get Current Price", "priceWatcher"), ("Check Sale", "isOnSale"), ("Get Current Inventory", "inventoryWatcher")]
    step_function = Parallel(
                        Name="Product Check",
                        Branches=[product_task(task[0], task[1]) for task in tasks)]
                        )
    print(step_function.to_asl_json())

This allows for considerable consolidation of the boilerplate and becomes more valuable if custom retry, catcher, item readers, or other components are reused across large state machines or for maintaining identical versions of state machines in multiple environments where resource arns can be provided via infrastructure as code without requiring multiple large messy JSON files to be kept in sync.

Roadmap

Currently, StepScribe uses pydantic models for state machine, states and major components and assumes only JSONata is being used (not JSONPath state attributes or query language) and writes these objects to the corresponding states language JSON. StepScribe also provides a load_asl_json that can take a JSON string or a filename for the JSON file and returns a state machine pydantic model.

The following features are planned:

  • Test coverage and documentation
  • JSONPath support
  • Write state machine to mermaidJS diagram
  • JSONata expression validation

Usage, desired features, bug reports, bug fixes, and feature implementations are welcome.

Contributing

For feature requests or bug reports, please submit an issue in GitHub with as much information as possible.

For bug fixes or feature implementations, fork the repo and create a PR to merge your fork branch here and request a review from me. See the contributions guide for more information.

License

MIT

Metadata

Release files for stepscribe 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stepscribe 0.4.0
File Size Uploaded Provenance Actions
stepscribe-0.4.0.tar.gz 6.8 kB Without provenance Details for stepscribe-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stepscribe 0.4.0
File Interpreter ABI Platform Actions
stepscribe-0.4.0-py3-none-any.whl Python 3 none any Details for stepscribe-0.4.0-py3-none-any.whl

Total release size: 14.2 kB

Release files / stepscribe-0.4.0.tar.gz

Download URL stepscribe-0.4.0.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d8b0b4c48c7d37c738282d9cbc0a8e5aa13c6ffbc0c8ebe184c99bf489240016
BLAKE2b-256 checksum
How to use checksums
01f18fe639eda2303871341861f0c965f092585cde5074c223efe3fa6fcb9803
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / stepscribe-0.4.0-py3-none-any.whl

Download URL stepscribe-0.4.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4971d270fb5d919ee6e9636f45fdc0b0ac645f15bc9ed31b8673ab00f64b361
BLAKE2b-256 checksum
How to use checksums
9d58d8c5c8616253137b0072566d48ca7e44a32549a4cb952059707e4c7a2c77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for stepscribe 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page