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.
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.
Name Description 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 runs 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. aio_run_manyRun a workflow in bulk asynchronously. 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. create_bulk_run_itemCreate a bulk run item for the workflow. This is intended to be used in conjunction with the various run_many methods. list_runsList runs of the workflow. aio_list_runsList runs of the workflow. create_filterCreate a new filter. aio_create_filterCreate a new filter.
The (namespaced) name of the workflow.
Get the ID of the workflow.
Type Description strThe ID of the workflow.
Type Description ValueErrorIf no workflow ID is found for the workflow name.
A decorator to transform a function into a Hatchet task that runs as part of a workflow.
Name Type Description Default namestr | NoneThe name of the task. If not specified, defaults to the name of the function being wrapped by the task decorator. Noneschedule_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. timedelta(minutes=5)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. timedelta(seconds=60)parentslist[Task[TWorkflowInput, Any]] | NoneA list of tasks that are parents of the task. Note: Parents must be defined before their children. NoneretriesintThe number of times to retry the task before failing. 0rate_limitslist[RateLimit] | NoneA list of rate limit configurations for the task. Nonedesired_worker_labelsdict[str, DesiredWorkerLabel] | list[DesiredWorkerLabel] | NoneA 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. Nonebackoff_factorfloat | NoneThe backoff factor for controlling exponential backoff in retries. Nonebackoff_max_secondsint | NoneThe maximum number of seconds to allow retries with exponential backoff to continue. Noneconcurrencyint | list[ConcurrencyExpression] | NoneA list of concurrency expressions for the task. If an integer is provided, it is treated as a constant concurrency limit with a GROUP_ROUND_ROBIN strategy, which means that only N runs of the task may execute at any given time. Nonewait_forlist[Condition | OrGroup] | NoneA list of conditions that must be met before the task can run. Noneskip_iflist[Condition | OrGroup] | NoneA list of conditions that, if met, will cause the task to be skipped. Nonecancel_iflist[Condition | OrGroup] | NoneA list of conditions that, if met, will cause the task to be canceled. None
Type Description Callable[[Callable[Concatenate[TWorkflowInput, Context, P], R | CoroutineLike[R]]], Task[TWorkflowInput, R]]A decorator which creates a Task object.
A decorator to transform a function into a durable Hatchet task that runs 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.
Name Type Description Default namestr | NoneThe name of the task. If not specified, defaults to the name of the function being wrapped by the task decorator. Noneschedule_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. timedelta(minutes=5)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. timedelta(seconds=60)parentslist[Task[TWorkflowInput, Any]] | NoneA list of tasks that are parents of the task. Note: Parents must be defined before their children. NoneretriesintThe number of times to retry the task before failing. 0rate_limitslist[RateLimit] | NoneA list of rate limit configurations for the task. Nonedesired_worker_labelsdict[str, DesiredWorkerLabel] | list[DesiredWorkerLabel] | NoneA 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. Nonebackoff_factorfloat | NoneThe backoff factor for controlling exponential backoff in retries. Nonebackoff_max_secondsint | NoneThe maximum number of seconds to allow retries with exponential backoff to continue. Noneconcurrencyint | list[ConcurrencyExpression] | NoneA list of concurrency expressions for the task. If an integer is provided, it is treated as a constant concurrency limit with a GROUP_ROUND_ROBIN strategy, which means that only N runs of the task may execute at any given time. Nonewait_forlist[Condition | OrGroup] | NoneA list of conditions that must be met before the task can run. Noneskip_iflist[Condition | OrGroup] | NoneA list of conditions that, if met, will cause the task to be skipped. Nonecancel_iflist[Condition | OrGroup] | NoneA list of conditions that, if met, will cause the task to be canceled. Noneeviction_policyEvictionPolicy | NoneAn optional eviction policy controlling when this durable task can be evicted from a worker slot while waiting. DEFAULT_DURABLE_TASK_EVICTION_POLICY
Type Description Callable[[Callable[Concatenate[TWorkflowInput, DurableContext, P], R | CoroutineLike[R]]], Task[TWorkflowInput, R]]A decorator which creates a Task object.
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.
Name Type Description Default 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. Noneschedule_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. timedelta(minutes=5)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. timedelta(seconds=60)retriesintThe number of times to retry the on-failure task before failing. 0rate_limitslist[RateLimit] | NoneA list of rate limit configurations for the on-failure task. Nonebackoff_factorfloat | NoneThe backoff factor for controlling exponential backoff in retries. Nonebackoff_max_secondsint | NoneThe maximum number of seconds to allow retries with exponential backoff to continue. Noneconcurrencyint | list[ConcurrencyExpression] | NoneA list of concurrency expressions for the on-failure task. If an integer is provided, it is treated as a constant concurrency limit with a GROUP_ROUND_ROBIN strategy, which means that only N runs of the task may execute at any given time. None
Type Description Callable[[Callable[Concatenate[TWorkflowInput, Context, P], R | CoroutineLike[R]]], Task[TWorkflowInput, R]]A decorator which creates a Task object.
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.
Name Type Description Default namestr | NoneThe name of the on-success task. If not specified, defaults to the name of the function being wrapped by the on_success_task decorator. Noneschedule_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. timedelta(minutes=5)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. timedelta(seconds=60)retriesintThe number of times to retry the on-success task before failing 0rate_limitslist[RateLimit] | NoneA list of rate limit configurations for the on-success task. Nonebackoff_factorfloat | NoneThe backoff factor for controlling exponential backoff in retries. Nonebackoff_max_secondsint | NoneThe maximum number of seconds to allow retries with exponential backoff to continue. Noneconcurrencyint | list[ConcurrencyExpression] | NoneA list of concurrency expressions for the on-success task. If an integer is provided, it is treated as a constant concurrency limit with a GROUP_ROUND_ROBIN strategy, which means that only N runs of the task may execute at any given time. None
Type Description Callable[[Callable[Concatenate[TWorkflowInput, Context, P], R | CoroutineLike[R]]], Task[TWorkflowInput, R]]A decorator which creates a Task object.
Run the workflow synchronously and wait for it to complete.
This method triggers a workflow run, blocks until completion, and returns the final result.
Name Type Description Default inputTWorkflowInputThe input data for the workflow, must match the workflow's input type. cast(TWorkflowInput, EmptyModel())optionsTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonewait_for_resultboolIf True, block until completion and return the result. If False, return a WorkflowRunRef immediately. Truechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the workflow run. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. Nonedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description WorkflowRunRef | dict[str, Any]The result of the workflow execution as a dictionary, or a WorkflowRunRef if wait_for_result is False.
Run the workflow asynchronously and wait for it to complete.
This method triggers a workflow run, awaits until completion, and returns the final result.
Name Type Description Default inputTWorkflowInputThe input data for the workflow, must match the workflow's input type. cast(TWorkflowInput, EmptyModel())optionsTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonewait_for_resultboolIf True, await completion and return the result. If False, return a WorkflowRunRef immediately. Truechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the workflow run. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. Nonedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description WorkflowRunRef | dict[str, Any]The result of the workflow execution as a dictionary, or a WorkflowRunRef if wait_for_result is False.
Type Description RuntimeErrorIf the workflow is triggered within a durable context that supports durable eviction but fails to spawn a durable child workflow.
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.
Name Type Description Default inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())optionsTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the workflow run. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. Nonedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description WorkflowRunRefA WorkflowRunRef object representing the reference to the workflow run. .. deprecated:: Use run(wait_for_result=False) instead.
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.
Name Type Description Default inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())optionsTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the workflow run. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. Nonedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description WorkflowRunRefA WorkflowRunRef object representing the reference to the workflow run. .. deprecated:: Use aio_run(wait_for_result=False) instead.
Run a workflow in bulk.
Name Type Description Default workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered. required return_exceptionsboolIf True, exceptions will be returned as part of the results instead of raising them. Falsewait_for_resultboolIf True, block until all runs complete and return results. If False, return a list of WorkflowRunRef immediately. True
Type Description list[dict[str, Any]] | list[dict[str, Any] | BaseException] | list[WorkflowRunRef]A list of results for each workflow run, or a list of WorkflowRunRef if wait_for_result is False.
Run a workflow in bulk asynchronously.
Name Type Description Default workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered. required return_exceptionsboolIf True, exceptions will be returned as part of the results instead of raising them. Falsewait_for_resultboolIf True, await completion and return results. If False, return a list of WorkflowRunRef immediately. True
Type Description list[dict[str, Any]] | list[dict[str, Any] | BaseException] | list[WorkflowRunRef]A list of results for each workflow run, or a list of WorkflowRunRef if wait_for_result is False.
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.
Name Type Description Default workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered. required
Type Description list[WorkflowRunRef]A list of WorkflowRunRef objects, each representing a reference to a workflow run. .. deprecated:: Use run_many(wait_for_result=False) instead.
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.
Name Type Description Default workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered. required
Type Description list[WorkflowRunRef]A list of WorkflowRunRef objects, each representing a reference to a workflow run. .. deprecated:: Use aio_run_many(wait_for_result=False) instead.
Schedule a workflow to run at a specific time.
Name Type Description Default run_atdatetimeThe time at which to schedule the workflow. required inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())optionsScheduleTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the scheduled workflow run. None
Type Description WorkflowVersionA WorkflowVersion object representing the scheduled workflow.
Schedule a workflow to run at a specific time.
Name Type Description Default run_atdatetimeThe time at which to schedule the workflow. required inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())optionsScheduleTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the scheduled workflow run. None
Type Description WorkflowVersionA WorkflowVersion object representing the scheduled workflow.
Create a cron job for the workflow.
Name Type Description Default 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_metadataJSONSerializableMapping | NoneAdditional metadata for the cron job. Nonepriorityint | Priority | NoneThe priority of the cron job. Must be between 1 and 3, inclusive. None
Type Description CronWorkflowsA CronWorkflows object representing the created cron job.
Create a cron job for the workflow.
Name Type Description Default 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_metadataJSONSerializableMapping | NoneAdditional metadata for the cron job. Nonepriorityint | Priority | NoneThe priority of the cron job. Must be between 1 and 3, inclusive. None
Type Description CronWorkflowsA CronWorkflows object representing the created cron job.
Create a bulk run item for the workflow. This is intended to be used in conjunction with the various run_many methods.
Name Type Description Default inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())keystr | NoneThe key for the workflow run. This is used to identify the run in the bulk operation and for deduplication. NoneoptionsTriggerWorkflowOptions | NoneDeprecated. Additional options for the workflow run. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. NonepriorityPriority | NoneThe priority of the workflow run. Nonedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description WorkflowRunTriggerConfigA WorkflowRunTriggerConfig object that can be used to trigger the workflow run, which you then pass into the run_many methods.
List runs of the workflow.
Name Type Description Default sincedatetime | NoneThe start time for the runs to be listed. Noneuntildatetime | NoneThe end time for the runs to be listed. NonelimitintThe maximum number of runs to be listed. 100offsetint | NoneThe offset for pagination. Nonestatuseslist[V1TaskStatus] | NoneThe statuses of the runs to be listed. Noneadditional_metadatadict[str, str] | NoneAdditional metadata for filtering the runs. Noneworker_idstr | NoneThe ID of the worker that ran the tasks. Noneparent_task_external_idstr | NoneThe external ID of the parent task. Noneonly_tasksboolWhether to list only task runs. Falsetriggering_event_external_idstr | NoneThe event id that triggered the task run. None
Type Description list[V1TaskSummary]A list of V1TaskSummary objects representing the runs of the workflow.
List runs of the workflow.
Name Type Description Default sincedatetime | NoneThe start time for the runs to be listed. Noneuntildatetime | NoneThe end time for the runs to be listed. NonelimitintThe maximum number of runs to be listed. 100offsetint | NoneThe offset for pagination. Nonestatuseslist[V1TaskStatus] | NoneThe statuses of the runs to be listed. Noneadditional_metadatadict[str, str] | NoneAdditional metadata for filtering the runs. Noneworker_idstr | NoneThe ID of the worker that ran the tasks. Noneparent_task_external_idstr | NoneThe external ID of the parent task. Noneonly_tasksboolWhether to list only task runs. Falsetriggering_event_external_idstr | NoneThe event id that triggered the task run. None
Type Description list[V1TaskSummary]A list of V1TaskSummary objects representing the runs of the workflow.
Create a new filter.
Name Type Description Default expressionstrThe expression to evaluate for the filter. required scopestrThe scope for the filter. required payloadJSONSerializableMapping | NoneThe payload to send with the filter. None
Type Description V1FilterThe created filter.
Create a new filter.
Name Type Description Default expressionstrThe expression to evaluate for the filter. required scopestrThe scope for the filter. required payloadJSONSerializableMapping | NoneThe payload to send with the filter. None
Type Description V1FilterThe created filter.
Bases: Generic[TWorkflowInput, R]
Name Description mock_runMimic the execution of a task. This method is intended to be used to unit test aio_mock_runMimic the execution of a task. This method is intended to be used to unit test
Mimic the execution of a task. This method is intended to be used to unit test tasks without needing to interact with the Hatchet engine. Use mock_run for sync tasks and aio_mock_run for async tasks.
Name Type Description Default inputTWorkflowInput | NoneThe input to the task. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the task. Noneparent_outputsdict[str, JSONSerializableMapping] | NoneOutputs from parent tasks, if any. This is useful for mimicking DAG functionality. For instance, if you have a task step_2 that has a parent which is step_1, you can pass parent_outputs={"step_1": {"result": "Hello, world!"}} to step_2.mock_run() to be able to access ctx.task_output(step_1) in step_2. Noneretry_countintThe number of times the task has been retried. 0lifespanAnyThe lifespan to be used in the task, which is useful if one was set on the worker. This will allow you to access ctx.lifespan inside of your task. Nonedependenciesdict[str, Any] | NoneDependencies to be injected into the task. This is useful for tasks that have dependencies defined using Depends. IMPORTANT : You must pass the dependencies directly , not the Depends objects themselves. For example, if you have a task that has a dependency config: Annotated[str, Depends(get_config)], you should pass dependencies={"config": "config_value"} to aio_mock_run. None
Type Description RThe output of the task.
Type Description TypeErrorIf the task is an async function and mock_run is called, or if the task is a sync function and aio_mock_run is called.
Mimic the execution of a task. This method is intended to be used to unit test tasks without needing to interact with the Hatchet engine. Use mock_run for sync tasks and aio_mock_run for async tasks.
Name Type Description Default inputTWorkflowInput | NoneThe input to the task. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the task. Noneparent_outputsdict[str, JSONSerializableMapping] | NoneOutputs from parent tasks, if any. This is useful for mimicking DAG functionality. For instance, if you have a task step_2 that has a parent which is step_1, you can pass parent_outputs={"step_1": {"result": "Hello, world!"}} to step_2.mock_run() to be able to access ctx.task_output(step_1) in step_2. Noneretry_countintThe number of times the task has been retried. 0lifespanAnyThe lifespan to be used in the task, which is useful if one was set on the worker. This will allow you to access ctx.lifespan inside of your task. Nonedependenciesdict[str, Any] | NoneDependencies to be injected into the task. This is useful for tasks that have dependencies defined using Depends. IMPORTANT : You must pass the dependencies directly , not the Depends objects themselves. For example, if you have a task that has a dependency config: Annotated[str, Depends(get_config)], you should pass dependencies={"config": "config_value"} to aio_mock_run. None
Type Description RThe output of the task.
Type Description TypeErrorIf the task is an async function and mock_run is called, or if the task is a sync function and aio_mock_run is called.
Bases: BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]
Name Description runRun the workflow synchronously and wait for it to complete. aio_runRun the workflow asynchronously and wait for it to complete. run_no_waitTrigger 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. aio_run_manyRun a workflow in bulk asynchronously. 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. create_bulk_run_itemCreate a bulk run item for the workflow. This is intended to be used in conjunction with the various run_many methods. list_runsList runs of the workflow. aio_list_runsList runs of the workflow. create_filterCreate a new filter. aio_create_filterCreate a new filter. deletePermanently delete the workflow. aio_deletePermanently delete the workflow. get_run_refGet a reference to a task run by its run ID. get_resultGet the result of a task run by its run ID. aio_get_resultGet the result of a task run by its run ID. mock_runMimic the execution of a task. This method is intended to be used to unit test aio_mock_runMimic the execution of a task. This method is intended to be used to unit test
Run the workflow synchronously and wait for it to complete.
This method triggers a workflow run, blocks until completion, and returns the extracted result.
Name Type Description Default inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())optionsTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonewait_for_resultboolIf True, block until completion and return the result. If False, return a TaskRunRef immediately. Truechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the workflow run. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. Nonedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description TaskRunRef[TWorkflowInput, R] | RThe extracted result of the workflow execution, or a TaskRunRef if wait_for_result is False.
Run the workflow asynchronously and wait for it to complete.
This method triggers a workflow run, awaits until completion, and returns the extracted result.
Name Type Description Default inputTWorkflowInputThe input data for the workflow, must match the workflow's input type. cast(TWorkflowInput, EmptyModel())optionsTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonewait_for_resultboolIf True, await completion and return the result. If False, return a TaskRunRef immediately. Truechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the workflow run. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. Nonedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description TaskRunRef[TWorkflowInput, R] | RThe extracted result of the workflow execution, or a TaskRunRef if wait_for_result is False.
Trigger a workflow run without waiting for it to complete.
This method triggers a workflow run and immediately returns a reference to the run without blocking while the workflow runs.
Name Type Description Default inputTWorkflowInputThe input data for the workflow, must match the workflow's input type. cast(TWorkflowInput, EmptyModel())optionsTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the workflow run. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. Nonedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description TaskRunRef[TWorkflowInput, R]A TaskRunRef object representing the reference to the workflow run. .. deprecated:: Use run(wait_for_result=False) instead.
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.
Name Type Description Default inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())optionsTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the workflow run. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. Nonedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description TaskRunRef[TWorkflowInput, R]A TaskRunRef object representing the reference to the workflow run. .. deprecated:: Use aio_run(wait_for_result=False) instead.
Run a workflow in bulk.
Name Type Description Default workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered. required return_exceptionsboolIf True, exceptions will be returned as part of the results instead of raising them. Falsewait_for_resultboolIf True, block until all runs complete and return results. If False, return a list of TaskRunRef immediately. True
Type Description list[R] | list[R | BaseException] | list[TaskRunRef[TWorkflowInput, R]]A list of results for each workflow run, or a list of TaskRunRef if wait_for_result is False.
Run a workflow in bulk asynchronously.
Name Type Description Default workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered. required return_exceptionsboolIf True, exceptions will be returned as part of the results instead of raising them. Falsewait_for_resultboolIf True, await completion and return results. If False, return a list of TaskRunRef immediately. True
Type Description list[R] | list[R | BaseException] | list[TaskRunRef[TWorkflowInput, R]]A list of results for each workflow run, or a list of TaskRunRef if wait_for_result is False.
Run a workflow in bulk without waiting for all runs to complete.
Name Type Description Default workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered. required
Type Description list[TaskRunRef[TWorkflowInput, R]]A list of TaskRunRef objects, each representing a reference to a workflow run. .. deprecated:: Use run_many(wait_for_result=False) instead.
Run a workflow in bulk without waiting for all runs to complete.
Name Type Description Default workflowslist[WorkflowRunTriggerConfig]A list of WorkflowRunTriggerConfig objects, each representing a workflow run to be triggered. required
Type Description list[TaskRunRef[TWorkflowInput, R]]A list of TaskRunRef objects, each representing a reference to a workflow run. .. deprecated:: Use aio_run_many(wait_for_result=False) instead.
Schedule a workflow to run at a specific time.
Name Type Description Default run_atdatetimeThe time at which to schedule the workflow. required inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())optionsScheduleTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the scheduled workflow run. None
Type Description WorkflowVersionA WorkflowVersion object representing the scheduled workflow.
Schedule a workflow to run at a specific time.
Name Type Description Default run_atdatetimeThe time at which to schedule the workflow. required inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())optionsScheduleTriggerWorkflowOptions | NoneDeprecated. Additional options for workflow execution. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. Nonepriorityint | NoneThe priority of the scheduled workflow run. None
Type Description WorkflowVersionA WorkflowVersion object representing the scheduled workflow.
Create a cron job for the workflow.
Name Type Description Default 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_metadataJSONSerializableMapping | NoneAdditional metadata for the cron job. Nonepriorityint | Priority | NoneThe priority of the cron job. Must be between 1 and 3, inclusive. None
Type Description CronWorkflowsA CronWorkflows object representing the created cron job.
Create a cron job for the workflow.
Name Type Description Default 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_metadataJSONSerializableMapping | NoneAdditional metadata for the cron job. Nonepriorityint | Priority | NoneThe priority of the cron job. Must be between 1 and 3, inclusive. None
Type Description CronWorkflowsA CronWorkflows object representing the created cron job.
Create a bulk run item for the workflow. This is intended to be used in conjunction with the various run_many methods.
Name Type Description Default inputTWorkflowInputThe input data for the workflow. cast(TWorkflowInput, EmptyModel())keystr | NoneThe key for the workflow run. This is used to identify the run in the bulk operation and for deduplication. NoneoptionsTriggerWorkflowOptions | NoneDeprecated. Additional options for the workflow run. Use the other keyword arguments instead. Nonechild_keystr | NoneAn optional key for deduplicating child workflow runs. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the workflow run. NonepriorityPriority | NoneThe priority of the workflow run. Nonedesired_worker_idstr | NoneThe ID of the desired worker to run the workflow on. NonestickyboolWhether to use sticky scheduling for the workflow run. Falsedesired_worker_labelslist[DesiredWorkerLabel] | NoneA list of desired worker labels for worker affinity. None
Type Description WorkflowRunTriggerConfigA WorkflowRunTriggerConfig object that can be used to trigger the workflow run, which you then pass into the run_many methods.
List runs of the workflow.
Name Type Description Default sincedatetime | NoneThe start time for the runs to be listed. Noneuntildatetime | NoneThe end time for the runs to be listed. NonelimitintThe maximum number of runs to be listed. 100offsetint | NoneThe offset for pagination. Nonestatuseslist[V1TaskStatus] | NoneThe statuses of the runs to be listed. Noneadditional_metadatadict[str, str] | NoneAdditional metadata for filtering the runs. Noneworker_idstr | NoneThe ID of the worker that ran the tasks. Noneparent_task_external_idstr | NoneThe external ID of the parent task. Noneonly_tasksboolWhether to list only task runs. Falsetriggering_event_external_idstr | NoneThe event id that triggered the task run. None
Type Description list[V1TaskSummary]A list of V1TaskSummary objects representing the runs of the workflow.
List runs of the workflow.
Name Type Description Default sincedatetime | NoneThe start time for the runs to be listed. Noneuntildatetime | NoneThe end time for the runs to be listed. NonelimitintThe maximum number of runs to be listed. 100offsetint | NoneThe offset for pagination. Nonestatuseslist[V1TaskStatus] | NoneThe statuses of the runs to be listed. Noneadditional_metadatadict[str, str] | NoneAdditional metadata for filtering the runs. Noneworker_idstr | NoneThe ID of the worker that ran the tasks. Noneparent_task_external_idstr | NoneThe external ID of the parent task. Noneonly_tasksboolWhether to list only task runs. Falsetriggering_event_external_idstr | NoneThe event id that triggered the task run. None
Type Description list[V1TaskSummary]A list of V1TaskSummary objects representing the runs of the workflow.
Create a new filter.
Name Type Description Default expressionstrThe expression to evaluate for the filter. required scopestrThe scope for the filter. required payloadJSONSerializableMapping | NoneThe payload to send with the filter. None
Type Description V1FilterThe created filter.
Create a new filter.
Name Type Description Default expressionstrThe expression to evaluate for the filter. required scopestrThe scope for the filter. required payloadJSONSerializableMapping | NoneThe payload to send with the filter. None
Type Description V1FilterThe created filter.
Permanently delete the workflow.
DANGEROUS: This will delete a workflow and all of its data
Permanently delete the workflow.
DANGEROUS: This will delete a workflow and all of its data
Get a reference to a task run by its run ID.
Name Type Description Default run_idstrThe ID of the run to get the reference for. required
Type Description TaskRunRef[TWorkflowInput, R]A TaskRunRef object representing the reference to the task run.
Get the result of a task run by its run ID.
Name Type Description Default run_idstrThe ID of the run to get the result for. required
Type Description RThe result of the task run.
Get the result of a task run by its run ID.
Name Type Description Default run_idstrThe ID of the run to get the result for. required
Type Description RThe result of the task run.
Mimic the execution of a task. This method is intended to be used to unit test tasks without needing to interact with the Hatchet engine. Use mock_run for sync tasks and aio_mock_run for async tasks.
Name Type Description Default inputTWorkflowInput | NoneThe input to the task. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the task. Noneparent_outputsdict[str, JSONSerializableMapping] | NoneOutputs from parent tasks, if any. This is useful for mimicking DAG functionality. For instance, if you have a task step_2 that has a parent which is step_1, you can pass parent_outputs={"step_1": {"result": "Hello, world!"}} to step_2.mock_run() to be able to access ctx.task_output(step_1) in step_2. Noneretry_countintThe number of times the task has been retried. 0lifespanAnyThe lifespan to be used in the task, which is useful if one was set on the worker. This will allow you to access ctx.lifespan inside of your task. Nonedependenciesdict[str, Any] | NoneDependencies to be injected into the task. This is useful for tasks that have dependencies defined using Depends. IMPORTANT : You must pass the dependencies directly , not the Depends objects themselves. For example, if you have a task that has a dependency config: Annotated[str, Depends(get_config)], you should pass dependencies={"config": "config_value"} to aio_mock_run. None
Type Description RThe output of the task.
Mimic the execution of a task. This method is intended to be used to unit test tasks without needing to interact with the Hatchet engine. Use mock_run for sync tasks and aio_mock_run for async tasks.
Name Type Description Default inputTWorkflowInput | NoneThe input to the task. Noneadditional_metadataJSONSerializableMapping | NoneAdditional metadata to attach to the task. Noneparent_outputsdict[str, JSONSerializableMapping] | NoneOutputs from parent tasks, if any. This is useful for mimicking DAG functionality. For instance, if you have a task step_2 that has a parent which is step_1, you can pass parent_outputs={"step_1": {"result": "Hello, world!"}} to step_2.mock_run() to be able to access ctx.task_output(step_1) in step_2. Noneretry_countintThe number of times the task has been retried. 0lifespanAnyThe lifespan to be used in the task, which is useful if one was set on the worker. This will allow you to access ctx.lifespan inside of your task. Nonedependenciesdict[str, Any] | NoneDependencies to be injected into the task. This is useful for tasks that have dependencies defined using Depends. IMPORTANT : You must pass the dependencies directly , not the Depends objects themselves. For example, if you have a task that has a dependency config: Annotated[str, Depends(get_config)], you should pass dependencies={"config": "config_value"} to aio_mock_run. None
Type Description RThe output of the task.