kashimiz / azure-functions-durable-python

A Python SDK for Durable Functions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NOTE: This repo houses a hackathon prototype. For the actual, officially-supported Durable Functions for Python library, please visit https://github.com/Azure/azure-functions-durable-python

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

About

A Python SDK for Durable Functions.

License:MIT License


Languages

Language:Python 100.0%