This directory contains examples of how to author durable orchestrations using the Durable Task Python SDK in conjunction with the Durable Task Scheduler (DTS).
If using a deployed Durable Task Scheduler:
There are two separate ways to run an example:
- Using the Emulator (recommended for learning and development)
- Using a deployed Scheduler and Taskhub in Azure
We recommend using the emulator for learning and development as it's faster to set up and doesn't require any Azure resources. The emulator simulates a scheduler and taskhub, packaged into an easy-to-use Docker container.
-
Install Docker: If it is not already installed.
-
Pull the Docker Image for the Emulator:
docker pull mcr.microsoft.com/dts/dts-emulator:latest
-
Run the Emulator: Wait a few seconds for the container to be ready.
docker run --name dtsemulator -d -p 8080:8080 mcr.microsoft.com/dts/dts-emulator:latest
-
Create a Python virtual environment (recommended):
python -m venv .venv
Activate the virtual environment:
Bash:
source .venv/bin/activatePowerShell:
.\.venv\Scripts\Activate.ps1
-
Install the Required Packages:
pip install -r requirements.txt
If you are running from a local clone of the repository, install the local packages in editable mode instead (run this from the repository root, not the
examples/directory):pip install -e . -e ./durabletask-azuremanaged
Note
The example code uses the default emulator settings
automatically (endpoint: http://localhost:8080, taskhub: default).
You don't need to set any environment variables.
For production scenarios or when you're ready to deploy to Azure, you can create a taskhub using the Azure CLI:
-
Create a Scheduler:
Bash:
az durabletask scheduler create \ --resource-group <testrg> \ --name <testscheduler> \ --location <eastus> \ --ip-allowlist "[0.0.0.0/0]" \ --sku-capacity 1 \ --sku-name "Dedicated" \ --tags "{'myattribute':'myvalue'}"
PowerShell:
az durabletask scheduler create ` --resource-group <testrg> ` --name <testscheduler> ` --location <eastus> ` --ip-allowlist "[0.0.0.0/0]" ` --sku-capacity 1 ` --sku-name "Dedicated" ` --tags "{'myattribute':'myvalue'}"
-
Create Your Taskhub:
Bash:
az durabletask taskhub create \ --resource-group <testrg> \ --scheduler-name <testscheduler> \ --name <testtaskhub>
PowerShell:
az durabletask taskhub create ` --resource-group <testrg> ` --scheduler-name <testscheduler> ` --name <testtaskhub>
-
Retrieve the Endpoint for the Scheduler: Locate the taskhub in the Azure portal to find the endpoint.
-
Set the Environment Variables:
Bash:
export TASKHUB=<taskhubname> export ENDPOINT=<taskhubEndpoint>
PowerShell:
$env:TASKHUB = "<taskhubname>" $env:ENDPOINT = "<taskhubEndpoint>"
-
Install the Required Packages:
pip install -r requirements.txt
You can now execute any of the examples in this directory using Python:
python activity_sequence.pyTo access the Durable Task Scheduler Dashboard, follow these steps:
-
Using the Emulator: By default, the dashboard runs on port 8082. Navigate to http://localhost:8082 and click on the default task hub.
-
Using a Deployed Scheduler: Navigate to the Scheduler resource. Then, go to the Task Hub subresource that you are using and click on the dashboard URL in the top right corner.