Skip to content
A Python SDK for Durable Functions.
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode sample bindings for durable python Jul 23, 2019
azure Merge pull request #17 from kashimiz/grpc Jul 26, 2019
samples Update sample app Jul 26, 2019
tests Fixing failing tests. Jul 24, 2019
.flake8 Added: examples Jul 23, 2019
.gitignore
LICENSE Initial commit Jul 16, 2019
README.md updated README file Jul 26, 2019
azure-pipelines.yml Update azure-pipelines script with grpc python autogeneration step Jul 24, 2019
requirements.txt building here Jul 24, 2019
setup.py Update sample app Jul 26, 2019

README.md

Durable Functions for Python

The azure-functions-durable pip package allows you to write Durable Functions for Python(https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node). Durable Functions is an extension of Azure Functions that lets you write stateful functions and workflows in a serverless environment. The extension manages state, checkpoints, and restarts for you. Durable Functions' advantages include:

  • Define workflows in code. No JSON schemas or designers are needed.
  • Call other functions synchronously and asynchronously. Output from called functions can be saved to local variables.
  • Automatically checkpoint progress whenever the function schedules async work. Local state is never lost if the process recycles or the VM reboots.

You can find more information at the following links:

A durable function, or orchestration, is a solution made up of different types of Azure Functions:

  • Activity: the functions and tasks being orchestrated by your workflow.
  • Orchestrator: a function that describes the way and order actions are executed in code.
  • Client: the entry point for creating an instance of a durable orchestration.

Durable Functions' function types and features are documented in-depth here.

Getting Started

You can follow the instructions below to get started with a function chaining example, or follow the general checklist below:

  1. Install prerequisites:

  2. Create an Azure Functions app.

  3. Install the Durable Functions extension

Run this command from the root folder of your Azure Functions app:

func extensions install -p Microsoft.Azure.WebJobs.Extensions.DurableTask -v 1.8.3

durable-functions requires Microsoft.Azure.WebJobs.Extensions.DurableTask 1.7.0 or greater.

  1. Install the azure-durable-functions pip package at the root of your function app:

Create and activate virtual environment

python3 -m venv env
source env/bin/activate
pip install azure-durable-functions
  1. Write an activity function (see sample):
def main(name: str) -> str:
    logging.info(f"Activity Triggered: {name}")
    # your code here
  1. Write an orchestrator function (see sample):
def main(context: str):
    orchestrate = df.Orchestrator.create(generator_function)
    result = orchestrate(context)
    return result

Note: Orchestrator functions must follow certain code constraints.

  1. Write your client function (see sample):

TBD

Note: Client functions are started by a trigger binding available in the Azure Functions 2.x major version. Read more about trigger bindings and 2.x-supported bindings.

Samples

The Durable Functions samples demonstrate several common use cases. They are located in the samples directory. Descriptive documentation is also available:

def generator_function(context):
    outputs = []
    task1 = yield context.df.callActivity("DurableActivity", "One")
    task2 = yield context.df.callActivity("DurableActivity", "Two")
    task3 = yield context.df.callActivity("DurableActivity", "Three")

    outputs.append(task1)
    outputs.append(task2)
    outputs.append(task3)

    return outputs
You can’t perform that action at this time.