Workflows SDK for Python
Usage and symbol reference
Render Workflows is in limited early access.
During the early access period, the Workflows API and SDK might introduce breaking changes.
The Render SDK for Python provides support for:
- Defining workflow tasks
- Triggering runs of those tasks from your other Python code
When triggering runs, you use different classes for asynchronous and synchronous execution contexts.
Install
Make sure to add render_sdk as a dependency to your application's requirements.txt, pyproject.toml, or equivalent.
Defining tasks
The following symbols pertain to creating and registering tasks in your workflow service. For guidance on how to use them, see Defining Workflow Tasks.
The Workflows class
Handles defining and registering workflow tasks. Initialize this in each file where you define tasks.
Initializing
Workflows(default_retry, default_timeout, default_plan)
Initializes a new Workflows object. All arguments are optional.
| Argument | Description |
|---|---|
|
A Individual tasks can override this. |
|
The default timeout (in seconds) for all tasks in this workflow. Individual tasks can override this. |
|
The default instance type to use for all tasks in this workflow. Individual task definitions can override this. The following instance types are available for all workspaces:
You can request access to the following additional instance types for your workspace:
|
Workflows.from_workflows(*apps, default_retry, default_timeout, default_plan)
Initializes a new Workflows object that incorporates tasks from one or more other Workflows objects.
Use this in your workflow's entry point file if you import task definitions from other files:
If you set any defaults with this method (such as default_timeout), those defaults apply only to tasks registered directly on this object (not to tasks registered on the imported objects).
| Argument | Description |
|---|---|
|
Required. One or more If two objects define a task with the same name, this raises a |
|
Default retry configuration for new tasks registered on the combined object. Same as the |
|
Default timeout for new tasks registered on the combined object. Same as the |
|
Default instance type for new tasks registered on the combined object. Same as the |
The @app.task decorator
You apply the @app.task decorator to a Python function to register it as a workflow task. For details, see Defining Workflow Tasks
Minimal example
Example with all arguments
Argument reference
| Option | Description |
|---|---|
|
Task decorator arguments | |
|
A custom name for the task. This affects the task's slug, which you use to reference the task when running it. If omitted, defaults to the name of the decorated function. |
|
A |
|
The timeout for the task's runs, in seconds. Must be between 30 seconds ( The default value is 2 hours. |
|
The default instance type to use for the task's runs. Supported values:
You can request access to the following additional instance types for your workspace:
The default value is |
|
Retry arguments | |
|
The maximum number of retries to attempt for a given run of the task. The total number of attempts is up to |
|
The base delay before attempting the first retry, in milliseconds. |
|
The exponential backoff factor. After each retry, the previous delay is multiplied by this factor. For example, a factor of
|
The app.start() method
The app.start() method serves as the entry point for your workflow during both task registration and run execution. Your workflow definition must call this method as part of startup:
This method takes no arguments.
Triggering runs (async)
Use the RenderAsync class to trigger and manage task runs from any asynchronous execution context (such as a FastAPI route handler). All methods are async and return awaitable objects.
The RenderAsync class
Constructor
RenderAsync(token)
Initializes a new RenderAsync object. All arguments are optional.
| Argument | Description |
|---|---|
|
The API key to use for authentication. If omitted, the client automatically detects and uses the value of the |
Task methods (async)
These methods are available on the workflows attribute of the RenderAsync class.
async workflows.start_task(task_identifier, input_data)
Kicks off a run of the registered task with the specified identifier, passing the specified arguments.
To instead run a task and wait for it to complete, use workflows.run_task.
On success: Returns an AwaitableTaskRun object representing the initial state of the task run. You can await this object to wait for the run to complete.
Raises: ClientError, ServerError, TimeoutError
| Argument | Description |
|---|---|
|
Required. The slug indicating the task to run, available from your task's page in the Render Dashboard:
Always has the format |
|
Required. A list or dictionary containing the task's input arguments.:
For a task that takes zero arguments, provide an empty list, |
async workflows.run_task(task_identifier, input_data)
Starts the registered task with the specified identifier, waits for it to complete, and returns the result.
To instead kick off a run without waiting for it to complete, use workflows.start_task.
On success: Returns a TaskRunDetails object for the completed task run.
Raises: ClientError, ServerError, TimeoutError, TaskRunError
| Argument | Description |
|---|---|
|
Required. The slug indicating the task to run, available from your task's page in the Render Dashboard:
Always has the format |
|
Required. A list or dictionary containing the task's input arguments.:
For a task that takes zero arguments, provide an empty list, |
async workflows.list_task_runs(params)
Lists task runs that match optional filters specified in the provided ListTaskRunsParams object.
On success: Returns a list of TaskRun objects.
Raises: ClientError, ServerError, TimeoutError
Supported fields of the ListTaskRunsParams object include:
| Parameter | Description |
|---|---|
|
Optional integer specifying the maximum number of task runs to return. |
|
Optional cursor string for pagination. Use this to retrieve the next page of results. |
|
Optional list of workspace IDs to filter results by. Only task runs from these workspaces will be returned. |
async workflows.get_task_run(task_run_id)
Retrieves the details of the task run with the specified ID.
On success: Returns a TaskRunDetails object.
Raises: ClientError, ServerError, TimeoutError
| Argument | Description |
|---|---|
|
Required. The ID of the task run to retrieve. Has the format |
async workflows.cancel_task_run(task_run_id)
Cancels the task run with the specified ID. This raises a ClientError if the task run is not found, or if it isn't currently running.
On success: Returns None.
Raises: ClientError, ServerError, TimeoutError
| Argument | Description |
|---|---|
|
Required. The ID of the task run to cancel. Has the format |
async workflows.task_run_events(task_run_ids)
Streams completion events for one or more task runs via Server-Sent Events (SSE). Returns an async iterator that yields a TaskRunDetails object each time a specified task run completes or fails.
The connection stays open until all events are received or you break out of the loop.
Raises: ClientError, ServerError, TimeoutError
| Argument | Description |
|---|---|
|
Required. A list of task run IDs to stream events for. Each ID has the format |
The AwaitableTaskRun class
Represents the initial state of a task run as returned by the async workflows.start_task method.
You can await this object to wait for the task run to complete. On success, it returns a TaskRunDetails object:
If the task run fails, this await raises a TaskRunError exception.
Properties
| Property | Description |
|---|---|
|
The ID of the task run. Has the format |
|
The initial status of the task run. This is usually |
Triggering runs (sync)
Use the Render class in any synchronous execution context (such as a default Flask or Django app). All methods are blocking.
The Render class
Constructor
Render(token)
Initializes a new Render object. All arguments are optional.
| Argument | Description |
|---|---|
|
The API key to use for authentication. If omitted, the client automatically detects and uses the value of the |
Task methods (sync)
These methods are available on the workflows attribute of the Render class.
workflows.start_task(task_identifier, input_data)
Runs the registered task with the specified identifier, passing the specified arguments.
To instead run a task and wait for it to complete, use workflows.run_task.
On success: Returns a TaskRun object representing the initial state of the task run (e.g. id, status). To wait for completion, poll workflows.get_task_run or use workflows.run_task.
Raises: ClientError, ServerError, TimeoutError
| Argument | Description |
|---|---|
|
Required. The slug indicating the task to run. Format: |
|
Required. A list or dictionary containing the task's input arguments. For zero arguments, use |
workflows.run_task(task_identifier, input_data)
Starts the task, waits for it to complete, and returns the result.
To instead kick off a run without waiting for it to complete, use workflows.start_task.
On success: Returns a TaskRunDetails object.
Raises: ClientError, ServerError, TimeoutError, TaskRunError
| Argument | Description |
|---|---|
|
Required. The slug indicating the task to run. Format: |
|
Required. A list or dictionary containing the task's input arguments. For zero arguments, use |
workflows.list_task_runs(params)
Lists task runs that match optional filters.
On success: Returns a list of TaskRun objects.
Raises: ClientError, ServerError, TimeoutError
Supported fields: limit, cursor, owner_id. See workflows.list_task_runs for parameter descriptions.
workflows.get_task_run(task_run_id)
Retrieves the details of the task run with the specified ID.
On success: Returns a TaskRunDetails object.
Raises: ClientError, ServerError, TimeoutError
| Argument | Description |
|---|---|
|
Required. The ID of the task run (format |
workflows.cancel_task_run(task_run_id)
Cancels the task run. Raises ClientError if not found or not running.
On success: Returns None.
Raises: ClientError, ServerError, TimeoutError
| Argument | Description |
|---|---|
|
Required. The ID of the task run to cancel (format |
workflows.task_run_events(task_run_ids)
Streams completion events via SSE. Returns a synchronous iterator that yields a TaskRunDetails object each time a specified task run completes or fails.
Raises: ClientError, ServerError, TimeoutError
| Argument | Description |
|---|---|
|
Required. List of task run IDs (format |
Additional types
The TaskRun class
Summarizes the state of a task run. Obtained in one of the following ways:
- From the sync
workflows.start_taskmethod - Calling the
workflows.list_task_runsmethod (sync or async)
To get a run's full details including results, call workflows.get_task_run (sync or async) and provide the run's ID to obtain a TaskRunDetails object.
Properties
| Property | Description |
|---|---|
|
The ID of the task run. Has the format |
|
The ID of the run's associated task. Has the format |
|
The initial status of the task run. This is usually |
|
The ID of this run's parent run, if this run was chained. For a root-level run, this value is the root run's ID or empty. |
|
The ID of the root task run in this run's execution chain. For a root-level run, this value matches |
|
The number of times the task run has retried so far. For a newly started run, this is typically |
|
A list of |
|
The datetime when the task run started executing. Not present if |
|
The datetime when the task run finished (successfully or otherwise). Present only if status is one of |
The TaskRunDetails class
Provides the full details of a task run. Obtained in one of the following ways:
-
awaiting anAwaitableTaskRunobject returned by the asyncworkflows.start_taskmethod: -
Calling the
workflows.run_taskmethod of theRenderorRenderAsyncclass: -
Calling the
workflows.get_task_runmethod of theRenderorRenderAsyncclass: -
Iterating over events from the
workflows.task_run_eventsmethod of theRenderorRenderAsyncclass:
Properties
A TaskRunDetails object includes all of the same properties as a TaskRun object, plus:
| Property | Description |
|---|---|
|
A list containing the task's return value(s). This value is always an empty list if |
|
The argument values that were passed to the task run, in the same format they were provided (as a list or a dictionary). Note the trailing underscore ( |
|
The error message if the task run failed. Present only if |
|
A list of |
Exception types
Exceptions raised by the SDK have one of the types listed below. RenderError is the parent class for all other exception types.
| Exception | Description |
|---|---|
|
The base class for all exceptions raised by the SDK. |
|
Raised when a request to the Render API returns a 400-level error code. Common causes include:
|
|
A subclass of |
|
Raised when a request to the Render API returns a 500-level error code. |
|
Raised when a request to the Render API times out. |
|
Raised when a task run fails (e.g. when |
