This directory contains examples of how to author durable orchestrations using the Durable Task Python SDK.
All the examples assume that you have a Durable Task-compatible sidecar running locally. There are two options for this:
-
Install the latest version of the Dapr CLI, which contains and exposes an embedded version of the Durable Task engine. The setup process (which requires Docker) will configure the workflow engine to store state in a local Redis container.
-
Run the Durable Task Sidecar project locally (requires Go 1.18 or higher). Orchestration state will be stored in a local sqlite database.
go install github.com/dapr/durabletask-go@main durabletask-go --port 4001
These examples can be tested automatically using mechanical-markdown, which validates that the examples run correctly and produce expected output.
To install mechanical-markdown:
python3 -m venv .venv
source .venv/bin/activate
pip install -e ../.
pip install mechanical-markdownTo see what commands would be run without executing them:
mm.py -d README.mdTo run all examples and validate their output:
mm.py README.mdWith one of the sidecars running, you can execute any of the examples in this directory using python3:
python3 ./activity_sequence.pyIn some cases, the sample may require command-line parameters or user inputs. In these cases, the sample will print out instructions on how to proceed.
This example demonstrates the function chaining pattern, where an orchestrator schedules three activity calls in a sequence.
python activity_sequence.pyThis example demonstrates parallel execution, where an orchestrator schedules a dynamic number of activity calls in parallel, waits for all of them to complete, and then performs an aggregation on the results.
python fanout_fanin.pyThis example demonstrates how an orchestrator can wait for external events (like human approval) with a timeout. If the approval isn't received within the specified timeout, the order is automatically cancelled.
{ sleep 2; printf '\n'; } | python human_interaction.py --timeout 20 --approver PYTHON-CI- Activity sequence: Orchestration that schedules three activity calls in a sequence.
- Fan-out/fan-in: Orchestration that schedules a dynamic number of activity calls in parallel, waits for all of them to complete, and then performs an aggregation on the results.
- Human interaction: Orchestration that waits for a human to approve an order before continuing.