Skip to main content

Task authoring and execution

In flytekit, a task is declared through TaskMetadata validation, executed via Task.local_execute, and wrapped for Python functions by PythonFunctionTask. Pass cache=True with cache_version set, or TaskMetadata.__post_init__ raises ValueError. For function tasks, PythonFunctionTask infers the interface and rejects nested functions unless the module is test_.

from flytekit import task

@task
def my_func(a: int) -> str:
return str(a)

Internally, Task.local_execute translates inputs with translate_inputs_to_literals, checks LocalTaskCache, and calls sandbox_execute -> dispatch_execute. PythonFunctionTask.execute invokes _task_function; ExecutionBehavior.DEFAULT runs directly, DYNAMIC calls dynamic_execute. TaskResolverMixin handles module loading with loader_args and load_task. IgnoreOutputs signals discardable outputs.