It’s not directly possible to call a task from another task, but you can call a task’s function from another task:
from prefect import flow, task, get_run_logger @task def my_first_task(msg): logger = get_run_logger() logger.info("Hello, %s!", msg) @task def my_second_task(msg): my_first_task.fn(msg) @flow def my_flow(): my_second_task("Marvin") if __name__ == "__main__": my_flow()
Note that this way, you are only calling the task’s function without actually generating a task run. It has a negative effect on observability - Prefect won’t track task execution in your Prefect backend if you call a task this way.
in the above example, you only run
my_second_task, which calls
my_first_task 's function, but it doesn’t trigger its task run – this could get confusing in the UI, so make sure to use that intentionally.