Define a workflow
Make a Python function a workflow by adding the@flow decorator to it:
Create tasks and child workflows
You can create tasks and child flows to organize your workflow logic.Cancel a workflow if it runs for too long
To apply a timeout to a flow or task to prevent it from running for too long, use thetimeout_seconds keyword argument.
Task timeout behavior
Task timeouts work differently depending on how the task is executed: Async tasks: Timeouts use cooperative cancellation atawait points. When the timeout is reached, the task is cancelled at the next await statement. This provides reliable timeout behavior for async code.
Sync tasks called directly: When a sync task is called directly (not via .submit()), it typically runs on the main thread where timeouts can use OS signals to interrupt execution, including blocking operations.
Sync tasks via .submit() with ThreadPoolTaskRunner: When a sync task is submitted using to a ThreadPoolTaskRunner (the default), it runs in a worker thread. In this context, timeouts cannot interrupt blocking operations like time.sleep(), network requests, or file I/O. The timeout will only take effect after the blocking operation completes naturally.
Configure flows and tasks
Flow configuration
All flows can be configured by passing arguments to the decorator. Flows accept the following optional settings:Task configuration
Tasks allow for customization through optional arguments that can be provided to the task decorator.
See all possible options in the Python SDK docs.
For example, provide optional
name and description arguments to a task:
task_run_name.Python’s standard string formatting syntax applies: