We use cookies

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.
Learn more.

SDK ReferencePython SDKRunnables

Runnables

Runnables in the Hatchet SDK are things that can be run, namely tasks and workflows. The two main types of runnables you’ll encounter are:

  • Workflow, which lets you define tasks and call all of the run, schedule, etc. methods
  • Standalone, which is a single task that’s returned by hatchet.task and can be run, scheduled, etc.

Workflow

Bases: BaseWorkflow[TWorkflowInput]

A Hatchet workflow, which allows you to define tasks to be run and perform actions on the workflow.

Workflows in Hatchet represent coordinated units of work that can be triggered, scheduled, or run on a cron schedule. Each workflow can contain multiple tasks that can be arranged in dependencies (DAGs), have customized retry behavior, timeouts, concurrency controls, and more.

Example:

from pydantic import BaseModel
from hatchet_sdk import Hatchet
 
class MyInput(BaseModel):
    name: str
 
hatchet = Hatchet()
workflow = hatchet.workflow("my-workflow", input_type=MyInput)
 
@workflow.task()
def greet(input, ctx):
    return f"Hello, {input.name}!"
 
# Run the workflow
result = workflow.run(MyInput(name="World"))

Workflows support various execution patterns including:

  • One-time execution with run() or aio_run()
  • Scheduled execution with schedule()
  • Cron-based recurring execution with create_cron()
  • Bulk operations with run_many()

Tasks within workflows can be defined with @workflow.task() or @workflow.durable_task() decorators and can be arranged into complex dependency patterns.

Methods:

NameDescription
taskA decorator to transform a function into a Hatchet task that runs as part of a workflow.
durable_taskA decorator to transform a function into a durable Hatchet task that run as part of a workflow.
on_failure_taskA decorator to transform a function into a Hatchet on-failure task that runs as the last step in a workflow that had at least one task fail.
on_success_taskA decorator to transform a function into a Hatchet on-success task that runs as the last step in a workflow that had all upstream tasks succeed.
runRun the workflow synchronously and wait for it to complete.
aio_runRun the workflow asynchronously and wait for it to complete.
run_no_waitSynchronously trigger a workflow run without waiting for it to complete.
aio_run_no_waitAsynchronously trigger a workflow run without waiting for it to complete.
run_manyRun a workflow in bulk and wait for all runs to complete.
aio_run_manyRun a workflow in bulk and wait for all runs to complete.
run_many_no_waitRun a workflow in bulk without waiting for all runs to complete.
aio_run_many_no_waitRun a workflow in bulk without waiting for all runs to complete.
scheduleSchedule a workflow to run at a specific time.
aio_scheduleSchedule a workflow to run at a specific time.
create_cronCreate a cron job for the workflow.
aio_create_cronCreate a cron job for the workflow.

Functions

task

A decorator to transform a function into a Hatchet task that runs as part of a workflow.

Parameters:

NameTypeDescriptionDefault
namestr | NoneThe name of the task. If not specified, defaults to the name of the function being wrapped by the task decorator.None
schedule_timeoutDurationThe maximum time to wait for the task to be scheduled. The run will be canceled if the task does not begin within this time.DEFAULT_SCHEDULE_TIMEOUT
execution_timeoutDurationThe maximum time to wait for the task to complete. The run will be canceled if the task does not complete within this time.DEFAULT_EXECUTION_TIMEOUT
parentslist[Task[TWorkflowInput, Any]]A list of tasks that are parents of the task. Note: Parents must be defined before their children.[]
retriesintThe number of times to retry the task before failing.0
rate_limitslist[RateLimit]A list of rate limit configurations for the task.[]
desired_worker_labelsdict[str, DesiredWorkerLabel]A dictionary of desired worker labels that determine to which worker the task should be assigned. See documentation and examples on affinity and worker labels for more details.{}
backoff_factorfloat | NoneThe backoff factor for controlling exponential backoff in retries.None
backoff_max_secondsint | NoneThe maximum number of seconds to allow retries with exponential backoff to continue.None
concurrencylist[ConcurrencyExpression]A list of concurrency expressions for the task.[]
wait_forlist[Condition | OrGroup]A list of conditions that must be met before the task can run.[]
skip_iflist[Condition | OrGroup]A list of conditions that, if met, will cause the task to be skipped.[]
cancel_iflist[Condition | OrGroup]A list of conditions that, if met, will cause the task to be canceled.[]

Returns:

TypeDescription
Callable[[Callable[[TWorkflowInput, Context], R]], Task[TWorkflowInput, R]]A decorator which creates a Task object.

durable_task

A decorator to transform a function into a durable Hatchet task that run as part of a workflow.

IMPORTANT: This decorator creates a durable task, which works using Hatchet’s durable execution capabilities. This is an advanced feature of Hatchet.

See the Hatchet docs for more information on durable execution to decide if this is right for you.

Parameters:

NameTypeDescriptionDefault
namestr | NoneThe name of the task. If not specified, defaults to the name of the function being wrapped by the task decorator.None
schedule_timeoutDurationThe maximum time to wait for the task to be scheduled. The run will be canceled if the task does not begin within this time.DEFAULT_SCHEDULE_TIMEOUT
execution_timeoutDurationThe maximum time to wait for the task to complete. The run will be canceled if the task does not complete within this time.DEFAULT_EXECUTION_TIMEOUT
parentslist[Task[TWorkflowInput, Any]]A list of tasks that are parents of the task. Note: Parents must be defined before their children.[]
retriesintThe number of times to retry the task before failing.0
rate_limitslist[RateLimit]A list of rate limit configurations for the task.[]
desired_worker_labelsdict[str, DesiredWorkerLabel]A dictionary of desired worker labels that determine to which worker the task should be assigned. See documentation and examples on affinity and worker labels for more details.{}
backoff_factorfloat | NoneThe backoff factor for controlling exponential backoff in retries.None
backoff_max_secondsint | NoneThe maximum number of seconds to allow retries with exponential backoff to continue.None
concurrencylist[ConcurrencyExpression]A list of concurrency expressions for the task.[]
wait_forlist[Condition | OrGroup]A list of conditions that must be met before the task can run.[]
skip_iflist[Condition | OrGroup]A list of conditions that, if met, will cause the task to be skipped.[]
cancel_iflist[Condition | OrGroup]A list of conditions that, if met, will cause the task to be canceled.[]

Returns:

TypeDescription
Callable[[Callable[[TWorkflowInput, DurableContext], R]], Task[TWorkflowInput, R]]A decorator which creates a Task object.

on_failure_task

A decorator to transform a function into a Hatchet on-failure task that runs as the last step in a workflow that had at least one task fail.

Parameters:

NameTypeDescriptionDefault
namestr | NoneThe name of the on-failure task. If not specified, defaults to the name of the function being wrapped by the on_failure_task decorator.None
schedule_timeoutDurationThe maximum time to wait for the task to be scheduled. The run will be canceled if the task does not begin within this time.DEFAULT_SCHEDULE_TIMEOUT
execution_timeoutDurationThe maximum time to wait for the task to complete. The run will be canceled if the task does not complete within this time.DEFAULT_EXECUTION_TIMEOUT
retriesintThe number of times to retry the on-failure task before failing.0
rate_limitslist[RateLimit]A list of rate limit configurations for the on-failure task.[]
backoff_factorfloat | NoneThe backoff factor for controlling exponential backoff in retries.None
backoff_max_secondsint | NoneThe maximum number of seconds to allow retries with exponential backoff to continue.None
concurrencylist[ConcurrencyExpression]A list of concurrency expressions for the on-success task.[]

Returns:

TypeDescription
Callable[[Callable[[TWorkflowInput, Context], R]], Task[TWorkflowInput, R]]A decorator which creates a Task object.

on_success_task

A decorator to transform a function into a Hatchet on-success task that runs as the last step in a workflow that had all upstream tasks succeed.

Parameters:

NameTypeDescriptionDefault
namestr | NoneThe name of the on-success task. If not specified, defaults to the name of the function being wrapped by the on_failure_task decorator.None
schedule_timeoutDurationThe maximum time to wait for the task to be scheduled. The run will be canceled if the task does not begin within this time.DEFAULT_SCHEDULE_TIMEOUT
execution_timeoutDurationThe maximum time to wait for the task to complete. The run will be canceled if the task does not complete within this time.DEFAULT_EXECUTION_TIMEOUT
retriesintThe number of times to retry the on-success task before failing0
rate_limitslist[RateLimit]A list of rate limit configurations for the on-success task.[]
backoff_factorfloat | NoneThe backoff factor for controlling exponential backoff in retries.None
backoff_max_secondsint | NoneThe maximum number of seconds to allow retries with exponential backoff to continue.None
concurrencylist[ConcurrencyExpression]A list of concurrency expressions for the on-success task.[]

Returns:

TypeDescription
Callable[[Callable[[TWorkflowInput, Context], R]], Task[TWorkflowInput, R]]A decorator which creates a Task object.

run

Run the workflow synchronously and wait for it to complete.

This method triggers a workflow run, blocks until completion, and returns the final result.

Parameters:

NameTypeDescriptionDefault
inputTWorkflowInputThe input data for the workflow, must match the workflow’s input type.cast(TWorkflowInput, EmptyModel())
optionsTriggerWorkflowOptionsAdditional options for workflow execution like metadata and parent workflow ID.TriggerWorkflowOptions()

Returns:

TypeDescription
dict[str, Any]The result of the workflow execution as a dictionary.

aio_run

Run the workflow asynchronously and wait for it to complete.

This method triggers a workflow run, blocks until completion, and returns the final result.

Parameters:

NameTypeDescriptionDefault
inputTWorkflowInputThe input data for the workflow, must match the workflow’s input type.cast(TWorkflowInput, EmptyModel())
optionsTriggerWorkflowOptionsAdditional options for workflow execution like metadata and parent workflow ID.TriggerWorkflowOptions()

Returns:

TypeDescription
dict[str, Any]The result of the workflow execution as a dictionary.

run_no_wait

Synchronously trigger a workflow run without waiting for it to complete. This method is useful for starting a workflow run and immediately returning a reference to the run without blocking while the workflow runs.

Parameters:

NameTypeDescriptionDefault
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
optionsTriggerWorkflowOptionsAdditional options for workflow execution.TriggerWorkflowOptions()

Returns:

TypeDescription
WorkflowRunRefA WorkflowRunRef object representing the reference to the workflow run.

aio_run_no_wait

Asynchronously trigger a workflow run without waiting for it to complete. This method is useful for starting a workflow run and immediately returning a reference to the run without blocking while the workflow runs.

Parameters:

NameTypeDescriptionDefault
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
optionsTriggerWorkflowOptionsAdditional options for workflow execution.TriggerWorkflowOptions()

Returns:

TypeDescription
WorkflowRunRefA WorkflowRunRef object representing the reference to the workflow run.

run_many

Run a workflow in bulk and wait for all runs to complete. This method triggers multiple workflow runs, blocks until all of them complete, and returns the final results.

Parameters:

NameTypeDescriptionDefault
workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered.required

Returns:

TypeDescription
list[dict[str, Any]]A list of results for each workflow run.

aio_run_many

Run a workflow in bulk and wait for all runs to complete. This method triggers multiple workflow runs, blocks until all of them complete, and returns the final results.

Parameters:

NameTypeDescriptionDefault
workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered.required

Returns:

TypeDescription
list[dict[str, Any]]A list of results for each workflow run.

run_many_no_wait

Run a workflow in bulk without waiting for all runs to complete. This method triggers multiple workflow runs and immediately returns a list of references to the runs without blocking while the workflows run.

Parameters:

NameTypeDescriptionDefault
workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered.required

Returns:

TypeDescription
list[WorkflowRunRef]A list of WorkflowRunRef objects, each representing a reference to a workflow run.

aio_run_many_no_wait

Run a workflow in bulk without waiting for all runs to complete. This method triggers multiple workflow runs and immediately returns a list of references to the runs without blocking while the workflows run.

Parameters:

NameTypeDescriptionDefault
workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered.required

Returns:

TypeDescription
list[WorkflowRunRef]A list of WorkflowRunRef objects, each representing a reference to a workflow run.

schedule

Schedule a workflow to run at a specific time.

Parameters:

NameTypeDescriptionDefault
run_atdatetimeThe time at which to schedule the workflow.required
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
optionsScheduleTriggerWorkflowOptionsAdditional options for workflow execution.ScheduleTriggerWorkflowOptions()

Returns:

TypeDescription
WorkflowVersionA WorkflowVersion object representing the scheduled workflow.

aio_schedule

Schedule a workflow to run at a specific time.

Parameters:

NameTypeDescriptionDefault
run_atdatetimeThe time at which to schedule the workflow.required
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
optionsScheduleTriggerWorkflowOptionsAdditional options for workflow execution.ScheduleTriggerWorkflowOptions()

Returns:

TypeDescription
WorkflowVersionA WorkflowVersion object representing the scheduled workflow.

create_cron

Create a cron job for the workflow.

Parameters:

NameTypeDescriptionDefault
cron_namestrThe name of the cron job.required
expressionstrThe cron expression that defines the schedule for the cron job.required
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
additional_metadataJSONSerializableMappingAdditional metadata for the cron job.{}
priorityint | NoneThe priority of the cron job. Must be between 1 and 3, inclusive.None

Returns:

TypeDescription
CronWorkflowsA CronWorkflows object representing the created cron job.

aio_create_cron

Create a cron job for the workflow.

Parameters:

NameTypeDescriptionDefault
cron_namestrThe name of the cron job.required
expressionstrThe cron expression that defines the schedule for the cron job.required
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
additional_metadataJSONSerializableMappingAdditional metadata for the cron job.{}
priorityint | NoneThe priority of the cron job. Must be between 1 and 3, inclusive.None

Returns:

TypeDescription
CronWorkflowsA CronWorkflows object representing the created cron job.

Standalone

Bases: BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]

Methods:

NameDescription
runSynchronously trigger a workflow run without waiting for it to complete.
aio_runRun the workflow asynchronously and wait for it to complete.
run_no_waitRun the workflow synchronously and wait for it to complete.
aio_run_no_waitAsynchronously trigger a workflow run without waiting for it to complete.
run_manyRun a workflow in bulk and wait for all runs to complete.
aio_run_manyRun a workflow in bulk and wait for all runs to complete.
run_many_no_waitRun a workflow in bulk without waiting for all runs to complete.
aio_run_many_no_waitRun a workflow in bulk without waiting for all runs to complete.
scheduleSchedule a workflow to run at a specific time.
aio_scheduleSchedule a workflow to run at a specific time.
create_cronCreate a cron job for the workflow.
aio_create_cronCreate a cron job for the workflow.

Functions

run

Synchronously trigger a workflow run without waiting for it to complete. This method is useful for starting a workflow run and immediately returning a reference to the run without blocking while the workflow runs.

Parameters:

NameTypeDescriptionDefault
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
optionsTriggerWorkflowOptionsAdditional options for workflow execution.TriggerWorkflowOptions()

Returns:

TypeDescription
RA WorkflowRunRef object representing the reference to the workflow run.

aio_run

Run the workflow asynchronously and wait for it to complete.

This method triggers a workflow run, blocks until completion, and returns the final result.

Parameters:

NameTypeDescriptionDefault
inputTWorkflowInputThe input data for the workflow, must match the workflow’s input type.cast(TWorkflowInput, EmptyModel())
optionsTriggerWorkflowOptionsAdditional options for workflow execution like metadata and parent workflow ID.TriggerWorkflowOptions()

Returns:

TypeDescription
RThe result of the workflow execution as a dictionary.

run_no_wait

Run the workflow synchronously and wait for it to complete.

This method triggers a workflow run, blocks until completion, and returns the final result.

Parameters:

NameTypeDescriptionDefault
inputTWorkflowInputThe input data for the workflow, must match the workflow’s input type.cast(TWorkflowInput, EmptyModel())
optionsTriggerWorkflowOptionsAdditional options for workflow execution like metadata and parent workflow ID.TriggerWorkflowOptions()

Returns:

TypeDescription
TaskRunRef[TWorkflowInput, R]The result of the workflow execution as a dictionary.

aio_run_no_wait

Asynchronously trigger a workflow run without waiting for it to complete. This method is useful for starting a workflow run and immediately returning a reference to the run without blocking while the workflow runs.

Parameters:

NameTypeDescriptionDefault
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
optionsTriggerWorkflowOptionsAdditional options for workflow execution.TriggerWorkflowOptions()

Returns:

TypeDescription
TaskRunRef[TWorkflowInput, R]A WorkflowRunRef object representing the reference to the workflow run.

run_many

Run a workflow in bulk and wait for all runs to complete. This method triggers multiple workflow runs, blocks until all of them complete, and returns the final results.

Parameters:

NameTypeDescriptionDefault
workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered.required

Returns:

TypeDescription
list[R]A list of results for each workflow run.

aio_run_many

Run a workflow in bulk and wait for all runs to complete. This method triggers multiple workflow runs, blocks until all of them complete, and returns the final results.

Parameters:

NameTypeDescriptionDefault
workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered.required

Returns:

TypeDescription
list[R]A list of results for each workflow run.

run_many_no_wait

Run a workflow in bulk without waiting for all runs to complete. This method triggers multiple workflow runs and immediately returns a list of references to the runs without blocking while the workflows run.

Parameters:

NameTypeDescriptionDefault
workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered.required

Returns:

TypeDescription
list[TaskRunRef[TWorkflowInput, R]]A list of WorkflowRunRef objects, each representing a reference to a workflow run.

aio_run_many_no_wait

Run a workflow in bulk without waiting for all runs to complete. This method triggers multiple workflow runs and immediately returns a list of references to the runs without blocking while the workflows run.

Parameters:

NameTypeDescriptionDefault
workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered.required

Returns:

TypeDescription
list[TaskRunRef[TWorkflowInput, R]]A list of WorkflowRunRef objects, each representing a reference to a workflow run.

schedule

Schedule a workflow to run at a specific time.

Parameters:

NameTypeDescriptionDefault
run_atdatetimeThe time at which to schedule the workflow.required
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
optionsScheduleTriggerWorkflowOptionsAdditional options for workflow execution.ScheduleTriggerWorkflowOptions()

Returns:

TypeDescription
WorkflowVersionA WorkflowVersion object representing the scheduled workflow.

aio_schedule

Schedule a workflow to run at a specific time.

Parameters:

NameTypeDescriptionDefault
run_atdatetimeThe time at which to schedule the workflow.required
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
optionsScheduleTriggerWorkflowOptionsAdditional options for workflow execution.ScheduleTriggerWorkflowOptions()

Returns:

TypeDescription
WorkflowVersionA WorkflowVersion object representing the scheduled workflow.

create_cron

Create a cron job for the workflow.

Parameters:

NameTypeDescriptionDefault
cron_namestrThe name of the cron job.required
expressionstrThe cron expression that defines the schedule for the cron job.required
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
additional_metadataJSONSerializableMappingAdditional metadata for the cron job.{}
priorityint | NoneThe priority of the cron job. Must be between 1 and 3, inclusive.None

Returns:

TypeDescription
CronWorkflowsA CronWorkflows object representing the created cron job.

aio_create_cron

Create a cron job for the workflow.

Parameters:

NameTypeDescriptionDefault
cron_namestrThe name of the cron job.required
expressionstrThe cron expression that defines the schedule for the cron job.required
inputTWorkflowInputThe input data for the workflow.cast(TWorkflowInput, EmptyModel())
additional_metadataJSONSerializableMappingAdditional metadata for the cron job.{}
priorityint | NoneThe priority of the cron job. Must be between 1 and 3, inclusive.None

Returns:

TypeDescription
CronWorkflowsA CronWorkflows object representing the created cron job.