{"id":7196,"library":"durabletask","title":"Durable Task SDK for Python","description":"The `durabletask` library is a Python Client SDK for the Azure Durable Task Scheduler, enabling developers to define, schedule, and manage resilient and stateful workflows (orchestrations) using ordinary Python code. It is designed for building fault-tolerant, long-running processes. The current version is 1.4.0, and the project maintains an active release cadence.","status":"active","version":"1.4.0","language":"python","source_language":"en","source_url":"https://github.com/microsoft/durabletask-python","tags":["workflow","orchestration","distributed","azure","task"],"install":[{"cmd":"pip install durabletask","lang":"bash","label":"Install core SDK"}],"dependencies":[],"imports":[{"wrong":"from durabletask import DurableTaskClient","symbol":"DurableTaskClient","correct":"from durabletask import task"},{"wrong":"","symbol":"OrchestrationWorkItemFilter","correct":"from durabletask import OrchestrationWorkItemFilter"},{"wrong":"","symbol":"ActivityWorkItemFilter","correct":"from durabletask import ActivityWorkItemFilter"}],"quickstart":{"code":"import os\nfrom durabletask import DurableTaskClient, DurableTaskWorker, OrchestrationContext, Task, TaskActivity\n\n# NOTE: For local development, ensure the Durable Task Scheduler emulator is running.\n# For example, using Docker: docker run --name dtsemulator -d -p 8080:8080 -p 8082:8082 mcr.microsoft.com/dts/dts-emulator:latest\nCONNECTION_STRING = os.environ.get(\"DURABLETASK_CONNECTION_STRING\", \"Endpoint=http://localhost:8080;Authentication=None\")\nTASK_HUB_NAME = os.environ.get(\"DURABLETASK_TASK_HUB_NAME\", \"default\")\n\nclass HelloActivity(TaskActivity):\n    async def run(self, context: OrchestrationContext, input: str) -> str:\n        print(f\"Executing HelloActivity with input: {input}\")\n        return f\"Hello, {input}!\"\n\nclass HelloOrchestrator(TaskActivity):\n    async def run(self, context: OrchestrationContext, input: str) -> str:\n        print(f\"Starting HelloOrchestrator with input: {input}\")\n        # Call an activity function\n        result = await context.call_activity(\"HelloActivity\", input)\n        print(f\"Orchestrator received result: {result}\")\n        return result\n\nasync def main():\n    client = DurableTaskClient(CONNECTION_STRING, TASK_HUB_NAME)\n    \n    # Register orchestrators and activities with the worker\n    worker = DurableTaskWorker(\n        CONNECTION_STRING,\n        TASK_HUB_NAME,\n        orchestrators={\n            \"HelloOrchestrator\": HelloOrchestrator()\n        },\n        activities={\n            \"HelloActivity\": HelloActivity()\n        }\n    )\n    \n    async with worker:\n        print(\"Worker started. Starting orchestration...\")\n        # Start a new orchestration\n        instance_id = await client.schedule_new_orchestration(\"HelloOrchestrator\", \"World\")\n        print(f\"Orchestration instance started: {instance_id}\")\n\n        # Wait for the orchestration to complete\n        status = await client.wait_for_orchestration_completion(instance_id, timeout_in_seconds=60)\n        if status:\n            print(f\"Orchestration '{instance_id}' completed. Status: {status.runtime_status}, Output: {status.output}\")\n        else:\n            print(f\"Orchestration '{instance_id}' did not complete within the timeout.\")\n\nif __name__ == \"__main__\":\n    import asyncio\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates a simple 'Hello World' orchestration. It defines an activity (`HelloActivity`) and an orchestrator (`HelloOrchestrator`), registers them with a worker, and then schedules a new orchestration instance using the client. It assumes a Durable Task Scheduler emulator is running locally on `http://localhost:8080` (e.g., via Docker) and uses environment variables for configuration."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or a later supported version.","message":"Python 3.9 support was removed in version 1.3.0. The library now requires Python 3.10 or newer.","severity":"breaking","affected_versions":">=1.3.0"},{"fix":"For current time, use `context.current_utc_datetime` or similar deterministic APIs provided by the SDK. Ensure all operations within orchestrators are replayable.","message":"Orchestrator functions must be deterministic. Avoid direct use of non-deterministic operations like `datetime.datetime.now()` or `random.random()` within orchestrator code, as this can lead to replay mismatches and unexpected behavior. Instead, use context-provided deterministic alternatives.","severity":"gotcha","affected_versions":"all"},{"fix":"Wrap calls to activities in `try/except` blocks within your orchestrator to handle individual activity failures gracefully. Inspect `TaskFailedException.FailureDetails` for root cause information. Python does not support custom retry handlers directly in orchestrators; implement retry logic with loops, exception handling, and timers.","message":"When using `context.task_all` (or `Task.all`) to run multiple activities in parallel, the orchestration will fail immediately upon the *first* activity's failure, even if other activities might succeed. Error details are encapsulated in `TaskFailedException`.","severity":"gotcha","affected_versions":"all"},{"fix":"For Azure Durable Functions, refer to the Azure Functions documentation and use the appropriate SDK for your language (e.g., `azure-functions-durable` for Python).","message":"This SDK is *not* directly compatible with Azure Durable Functions. If you are building Durable Functions, use the `azure-functions-durable` package and its associated tools. This SDK targets the standalone Durable Task Scheduler.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure the connection string matches the expected format: `Endpoint=http://localhost:8080;Authentication=None` for the local emulator (note `http` and port 8080) or `Endpoint=https://<scheduler-name>.durabletask.io;...` for Azure (note `https`). Verify `Authentication` parameter and port usage.","message":"Incorrect connection string formats are a common cause of startup failures, especially when switching between local development (emulator) and Azure deployments.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'1.4.0':52 'activ':58 'azur':16,64 'build':40 'cadenc':60 'client':12 'code':35 'current':49 'defin':23 'design':38 'develop':21 'distribut':63 'durabl':1,17 'durabletask':7 'enabl':20 'fault':42 'fault-toler':41 'librari':8 'long':45 'long-run':44 'maintain':56 'manag':26 'orchestr':31,62 'ordinari':33 'process':47 'project':55 'python':5,11,34 'releas':59 'resili':27 'run':46 'schedul':19,24 'sdk':3,13 'state':29 'task':2,18,65 'toler':43 'use':32 'version':50 'workflow':30,61","created_at":"2026-04-16T13:47:51.916243+00:00","updated_at":"2026-04-16T13:47:51.916243+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.5.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/microsoft/durabletask-python","docs":null,"changelog":"https://github.com/microsoft/durabletask-python/blob/main/CHANGELOG.md","pypi":"https://pypi.org/project/durabletask/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["azure","workflow"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}