Workflows SDK for Python
Symbol reference
Render Workflows are in limited early access.
During the early access period, the Workflows API and SDK might introduce breaking changes.
Render provides a Python SDK that supports both registering workflow tasks and executing those tasks from application code.
Install
Make sure to add render_sdk
as a dependency to your application's requirements.txt
file (or equivalent).
The @task
decorator
You apply the @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 |
---|---|
Top-level 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. |
|
Contains all other arguments for the task definition. Currently supports a single argument: |
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 start
function
The start
function serves as the entry point for your workflow during both task registration and task execution. Your workflow definition must call this function as part of startup:
This function takes no arguments.
The Client
class
The render_sdk.client.Client
class provides methods for running registered tasks from Python applications (such as a Render web service or cron job):
Constructor
Initializes a new Client
instance. 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 |
|
The base URL to use for task-related requests. Specify only for local development. If omitted:
|
If you don't provide an API key, the client will automatically detect and use the value of the RENDER_API_KEY
environment variable (if set).
Task methods
All methods below are async
.
Runs the registered task with the specified identifier, passing the specified arguments.
On success: Returns an AwaitableTaskRun
object representing the initial state of the task run.
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 containing values for the task's input arguments. For a task that takes zero arguments, provide an empty list, |
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
Retrieves the details of the task run with the specified ID.
On success: Returns a TaskRunDetails
object.
Raises: ClientError
, ServerError
, TimeoutError
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
The AwaitableTaskRun
class
Represents the initial state of a task run as returned by the workflows.run_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 |
The TaskRunDetails
class
Represents the current state of a task run. Obtained in one of the following ways:
-
await
ing anAwaitableTaskRun
object returned byworkflows.run_task
: -
Calling the
workflows.get_task_run
method:
Properties
Property | Description |
---|---|
|
The ID of the task run. Has the format |
|
The ID of the run's associated task. Has the format |
|
A list containing the argument values that were passed to the task run. Note the trailing underscore ( |
|
The current status of the task run. One of the following:
|
|
The task's return value. Present only if |
|
The ID of the parent task run, if this task was called as a subtask by another task. For a root-level task, this value is |
|
The ID of the root task run in this run's execution chain. For a root-level task, this value matches the value of |
|
The number of times the task run has retried. For runs that succeed without retries, this value is |
Exception types
Exceptions raised by the SDK have one of the types listed below. RenderError
is the parent class for all other exception types.