Workflows¶
workflows
¶
@workflow decorator and Workflow class for eager task entry points.
SyncWorkflow
dataclass
¶
Bases: BaseWorkflow[P, R]
Workflow wrapping a synchronous function.
Calling an instance sets up a session, executes the function, and returns its result.
Source code in src/daglite/workflows.py
AsyncWorkflow
dataclass
¶
Bases: BaseWorkflow[P, R]
Workflow wrapping an async coroutine function.
Calling an instance returns a coroutine that sets up an async_session, executes the function,
and returns its result.
Source code in src/daglite/workflows.py
workflow
¶
Decorator to convert a Python function into a daglite workflow.
Workflows are named entry points that wrap a function calling @task-decorated functions.
Tasks execute eagerly inside the workflow — they run immediately and return real values.
Calling a workflow sets up a managed session that provides backend, cache, plugin, and event
infrastructure. Sync workflows return the result directly; async workflows return a coroutine
that the caller must await.
Note that workflows cannot wrap generator functions. Use @task for generator functions or
collect results inside the workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Any
|
The function to wrap. When used without parentheses ( |
None
|
name
|
str | None
|
Custom name for the workflow. Defaults to the function's |
None
|
description
|
str | None
|
Workflow description. Defaults to the function's docstring. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A |
Any
|
(when used as |
Examples:
>>> from daglite import task, workflow
>>> @task
... def add(x: int, y: int) -> int:
... return x + y
>>> @task
... def mul(x: int, y: int) -> int:
... return x * y
Single-value workflow
Multi-step workflow
>>> @workflow
... def chain_workflow(x: int, y: int):
... a = add(x=x, y=y)
... return mul(x=a, y=10)
>>> chain_workflow(2, 3)
50