You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repo contains a Python client SDK for use with the [Durable Task Framework for Go](https://github.com/microsoft/durabletask-go) and [Dapr Workflow](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-overview/). With this SDK, you can define, schedule, and manage durable orchestrations using ordinary Python code.
8
8
9
+
> **🚀 Enhanced Async Features**: This fork includes comprehensive async workflow enhancements with advanced error handling, non-determinism detection, timeout support, and debugging tools. See [ASYNC_ENHANCEMENTS.md](./ASYNC_ENHANCEMENTS.md) for details.
10
+
11
+
## Quick Start - Async Workflows
12
+
13
+
For async workflow development, use the new `durabletask.aio` package:
result =await ctx.call_activity(say_hello, input=name)
21
+
await ctx.sleep(1.0)
22
+
returnf"Workflow completed: {result}"
23
+
24
+
defsay_hello(ctx, name: str) -> str:
25
+
returnf"Hello, {name}!"
26
+
27
+
# Register and run
28
+
with TaskHubGrpcWorker() as worker:
29
+
worker.add_activity(say_hello)
30
+
worker.add_orchestrator(my_workflow)
31
+
worker.start()
32
+
# ... schedule workflows with client
33
+
```
34
+
9
35
⚠️ **This SDK is currently under active development and is not yet ready for production use.** ⚠️
10
36
11
37
> Note that this project is **not** currently affiliated with the [Durable Functions](https://docs.microsoft.com/azure/azure-functions/durable/durable-functions-overview) project for Azure Functions. If you are looking for a Python SDK for Durable Functions, please see [this repo](https://github.com/Azure/azure-functions-durable-python).
@@ -155,6 +181,13 @@ python3 -m pip install .
155
181
156
182
See the [examples](./examples) directory for a list of sample orchestrations and instructions on how to run them.
157
183
184
+
**Enhanced Async Examples:**
185
+
-`async_activity_sequence.py` - Updated to use new `durabletask.aio` package
186
+
-`async_fanout_fanin.py` - Updated to use new `durabletask.aio` package
187
+
-`async_enhanced_features.py` - Comprehensive demo of all enhanced features
- See [ASYNC_ENHANCEMENTS.md](./ASYNC_ENHANCEMENTS.md) for detailed examples and usage patterns
190
+
158
191
## Development
159
192
160
193
The following is more information about how to develop this project. Note that development commands require that `make` is installed on your local machine. If you're using Windows, you can install `make` using [Chocolatey](https://chocolatey.org/) or use WSL.
For a deeper tour of the async authoring surface (determinism helpers, sandbox modes, timeouts, concurrency patterns), see the Async Enhancements guide: [ASYNC_ENHANCEMENTS.md](./ASYNC_ENHANCEMENTS.md). The developer-facing migration notes are in [DEVELOPER_TRANSITION_GUIDE.md](./DEVELOPER_TRANSITION_GUIDE.md).
211
246
212
-
You can author orchestrators with `async def` using `add_async_orchestrator`, which provides awaitables for activities, timers, external events, and when_all/any:
247
+
You can author orchestrators with `async def` using the new `durabletask.aio` package, which provides a comprehensive async workflow API:
Optional sandbox mode (`best_effort` or `strict`) patches `asyncio.sleep`, `random`, `uuid.uuid4`, and `time.time` within the workflow step to deterministic equivalents. This is best-effort and not a correctness guarantee.
228
264
229
-
In `strict` mode, `asyncio.create_task` is blocked inside workflows to preserve determinism and will raise a `RuntimeError` if used.
265
+
In `strict` mode, `asyncio.create_task` is blocked inside workflows to preserve determinism and will raise a `SandboxViolationError` if used.
266
+
267
+
> **Enhanced Sandbox Features**: The enhanced version includes comprehensive non-determinism detection, timeout support, enhanced concurrency primitives, and debugging tools. See [ASYNC_ENHANCEMENTS.md](./ASYNC_ENHANCEMENTS.md) for complete documentation.
230
268
231
269
#### Async patterns
232
270
271
+
- Activities and sub-orchestrations can be referenced by function object or by their registered string name. Both forms are supported:
272
+
- Function reference (preferred for IDE/type support) or string name (useful across modules/languages).
273
+
233
274
- Activities:
234
275
```python
235
-
result =await ctx.activity("process", input={"x": 1})
276
+
result =await ctx.call_activity("process", input={"x": 1})
277
+
# or: result = await ctx.call_activity(process, input={"x": 1})
236
278
```
237
279
238
280
- Timers:
@@ -247,29 +289,98 @@ val = await ctx.wait_for_external_event("approval")
- Async authoring (`durabletask.aio`): awaiting returns the operation's value. Exceptions are raised on `await` (no `is_failed`).
305
+
- Generator authoring (`durabletask.task`): yielding returns `Task` objects. Use `get_result()` to read values; failures surface via `is_failed()` or by raising on `get_result()`.
306
+
307
+
Examples:
308
+
309
+
```python
310
+
# Async authoring (await returns value)
311
+
# when_any returns a proxy that compares equal to the original awaitable
312
+
# and exposes get_result() for the completed item.
- Useful for routing, observability, and cross-cutting concerns passed along activity/sub-orchestrator calls via the sidecar.
375
+
- In python-sdk, available for both async and generator orchestrators. In this repo, currently implemented on `durabletask.aio`; generator parity is planned.
376
+
266
377
#### Worker readiness
267
378
268
379
When starting a worker and scheduling immediately, wait for the connection to the sidecar to be established:
0 commit comments