Skip to main content

TaskTemplate

Task template is a template for a task that can be executed. It defines various parameters for the task, which can be defined statically at the time of task definition or dynamically at the time of task invocation using the override method.

Attributes

AttributeTypeDescription
namestrThe name of the task (defaults to the function name).
interface[NativeInterface](../models/nativeinterface.md?sid=flyte_models_nativeinterface)The native interface for the task, defining its inputs and outputs.
short_namestr = ""A shorter name for the task, defaulting to the task's name if not explicitly set.
task_typestr = "python"The router type for the task, used to determine how the task will be executed and typically matches the execution plugin.
task_type_versionint = 0The version of the task type, used for compatibility and evolution of task definitions.
image`Union[str, Image, Literal["auto"]]None` = "auto"
resourcesOptional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = nullThe resources to use for the task, such as CPU and memory allocations.
cacheCacheRequest = "disable"The cache policy for the task; defaults to 'disable', which means task results will not be cached.
interruptiblebool = falseThe interruptible policy for the task; defaults to False, meaning the task will not be scheduled on interruptible nodes.
retriesUnion[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = 0The number of retries for the task; defaults to 0, meaning no retries will be attempted.
reusableUnion[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), None] = nullThe reusability policy for the task; defaults to None, meaning the task environment will not be reused across invocations.
docsOptional[Documentation] = nullThe documentation for the task; if not provided, the function docstring will be used.
env_varsOptional[Dict[str, str]] = nullThe environment variables to set for the task, affecting its execution environment.
secretsOptional[SecretRequest] = nullThe secrets that will be injected into the task at runtime, providing secure access to sensitive information.
timeoutOptional[TimeoutType] = nullThe timeout for the task, after which the task will be terminated if not completed.
pod_templateOptional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = nullThe pod template to use for the task, allowing customization of the Kubernetes pod configuration.
reportbool = falseWhether to report the task execution to the Flyte console; defaults to False.
queueOptional[str] = nullThe queue to use for the task; if not provided, the default queue will be used for scheduling.
debuggablebool = falseWhether the task supports debugging capabilities; defaults to False.
entrypointbool = falseA boolean indicating if this task is the entrypoint for a workflow.
parent_envOptional[weakref.ReferenceType[[TaskEnvironment](environment/taskenvironment.md?sid=flyte__task_environment_taskenvironment)]] = nullA weak reference to the parent task environment, used to manage task hierarchy and resource sharing.
parent_env_nameOptional[str] = nullThe name of the parent environment, used for contextual information.
refbool = falseA boolean flag indicating if this task template is a reference to another task.
max_inline_io_bytesint = MAX_INLINE_IO_BYTESMaximum allowed size (in bytes) for all inputs and outputs passed directly to the task (e.g., primitives, strings, dicts).
triggersTuple[[Trigger](../remote/trigger/trigger.md?sid=flyte_remote__trigger_trigger), ...] = tupleA tuple of Trigger objects that define conditions for task execution.
linksTuple[[Link](../app/types/link.md?sid=flyte_app__types_link), ...] = tupleA tuple of Link objects associated with the task, providing external references or connections.

Constructor

Signature

def TaskTemplate(
name: str = null,
task_type: str = null,
image: Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"]]| None = null,
resources: Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = null,
cache: CacheRequest = null,
interruptible: bool = null,
retries: Union[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = null,
reusable: Union[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), None] = null,
docs: Optional[Documentation] = null,
env_vars: Optional[Dict[str, str]] = null,
secrets: Optional[SecretRequest] = null,
timeout: Optional[TimeoutType] = null,
max_inline_io_bytes: int = null,
pod_template: Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = null,
report: bool = null,
queue: Optional[str] = null,
debuggable: bool = null
) - > null

Parameters

NameTypeDescription
namestr = nullOptional The name of the task (defaults to the function name)
task_typestr = nullRouter type for the task, this is used to determine how the task will be executed. This is usually set to match with th execution plugin.
image`Union[str, Image, Literal["auto"]]None` = null
resourcesOptional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = nullOptional The resources to use for the task
cacheCacheRequest = nullOptional The cache policy for the task, defaults to auto, which will cache the results of the task.
interruptiblebool = nullOptional The interruptible policy for the task, defaults to False, which means the task will not be scheduled on interruptible nodes. If set to True, the task will be scheduled on interruptible nodes, and the code should handle interruptions and resumptions.
retriesUnion[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = nullOptional The number of retries for the task, defaults to 0, which means no retries.
reusableUnion[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), None] = nullOptional The reusability policy for the task, defaults to None, which means the task environment will not be reused across task invocations.
docsOptional[Documentation] = nullOptional The documentation for the task, if not provided the function docstring will be used.
env_varsOptional[Dict[str, str]] = nullOptional The environment variables to set for the task.
secretsOptional[SecretRequest] = nullOptional The secrets that will be injected into the task at runtime.
timeoutOptional[TimeoutType] = nullOptional The timeout for the task.
max_inline_io_bytesint = nullMaximum allowed size (in bytes) for all inputs and outputs passed directly to the task (e.g., primitives, strings, dicts). Does not apply to files, directories, or dataframes.
pod_templateOptional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = nullOptional The pod template to use for the task.
reportbool = nullOptional Whether to report the task execution to the Flyte console, defaults to False.
queueOptional[str] = nullOptional The queue to use for the task. If not provided, the default queue will be used.
debuggablebool = nullOptional Whether the task supports debugging capabilities, defaults to False.

Methods


source_file()

@classmethod
def source_file() - > Optional[str]

Retrieves the source file path associated with the task template. This property is currently not implemented and always returns None.

Returns

TypeDescription
Optional[str]Always returns None, as the source file path is not currently tracked.

pre()

@classmethod
def pre(
args: Any,
kwargs: Any
) - > Dict[str, Any]

This is the preexecute function that will be called before the task is executed

Parameters

NameTypeDescription
argsAnyPositional arguments passed to the task.
kwargsAnyKeyword arguments passed to the task.

Returns

TypeDescription
Dict[str, Any]An empty dictionary, as this method currently performs no pre-execution setup.

execute()

@classmethod
def execute(
args: Any,
kwargs: Any
) - > Any

This is the pure python function that will be executed when the task is called.

Parameters

NameTypeDescription
argsAnyPositional arguments passed to the task's execution.
kwargsAnyKeyword arguments passed to the task's execution.

Returns

TypeDescription
AnyThe result of the task's execution.

post()

@classmethod
def post(
return_vals: Any
) - > Any

This is the postexecute function that will be called after the task is executed

Parameters

NameTypeDescription
return_valsAnyThe values returned by the task's execute method.

Returns

TypeDescription
AnyThe return values from the task's execution.

config()

@classmethod
def config(
sctx: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > Dict[str, str]

Returns additional configuration for the task. This is a set of key-value pairs that can be used to configure the task execution environment at runtime. This is usually used by plugins.

Parameters

NameTypeDescription
sctx[SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)The serialization context, providing information for serialization.

Returns

TypeDescription
Dict[str, str]An empty dictionary, as this method currently provides no additional configuration.

custom_config()

@classmethod
def custom_config(
sctx: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > Dict[str, str]

Returns additional configuration for the task. This is a set of key-value pairs that can be used to configure the task execution environment at runtime. This is usually used by plugins.

Parameters

NameTypeDescription
sctx[SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)The serialization context, providing information for serialization.

Returns

TypeDescription
Dict[str, str]An empty dictionary, as this method currently provides no custom configuration.

data_loading_config()

@classmethod
def data_loading_config(
sctx: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > DataLoadingConfig

This configuration allows executing raw containers in Flyte using the Flyte CoPilot system Flyte CoPilot, eliminates the needs of sdk inside the container. Any inputs required by the users container are side-loaded in the input_path Any outputs generated by the user container - within output_path are automatically uploaded

Parameters

NameTypeDescription
sctx[SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)The serialization context, providing information for serialization.

Returns

TypeDescription
DataLoadingConfigThe data loading configuration for the task.

container_args()

@classmethod
def container_args(
sctx: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > List[str]

Returns the container args for the task. This is a set of key-value pairs that can be used to configure the task execution environment at runtime. This is usually used by plugins.

Parameters

NameTypeDescription
sctx[SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)The serialization context, providing information for serialization.

Returns

TypeDescription
List[str]An empty list, as this method currently provides no container arguments.

sql()

@classmethod
def sql(
sctx: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > Optional[str]

Returns the SQL for the task. This is a set of key-value pairs that can be used to configure the task execution environment at runtime. This is usually used by plugins.

Parameters

NameTypeDescription
sctx[SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)The serialization context, providing information for serialization.

Returns

TypeDescription
Optional[str]Always returns None, as this method currently provides no SQL.

native_interface()

@classmethod
def native_interface() - > [NativeInterface](../models/nativeinterface.md?sid=flyte_models_nativeinterface)

Provides access to the native interface of the task template. This interface defines the inputs and outputs of the task.

Returns

TypeDescription
[NativeInterface](../models/nativeinterface.md?sid=flyte_models_nativeinterface)The native interface object associated with this task template.

aio()

@classmethod
def aio(
args: P.args,
kwargs: P.kwargs
) - > Coroutine[Any, Any, R]| R

The aio function allows executing "sync" tasks, in an async context. This helps with migrating v1 defined sync tasks to be used within an asyncio parent task. This function will also re-raise exceptions from the underlying task.

Parameters

NameTypeDescription
argsP.argsPositional arguments to pass to the underlying task.
kwargsP.kwargsKeyword arguments to pass to the underlying task.

Returns

TypeDescription
`Coroutine[Any, Any, R]R`

forward()

@classmethod
def forward(
args: P.args,
kwargs: P.kwargs
) - > Coroutine[Any, Any, R]| R

Think of this as a local execute method for your task. This function will be invoked by the call method when not in a Flyte task execution context. See the implementation below for an example.

Parameters

NameTypeDescription
argsP.argsPositional arguments to pass to the task.
kwargsP.kwargsKeyword arguments to pass to the task.

Returns

TypeDescription
`Coroutine[Any, Any, R]R`

override()

@classmethod
def override(
short_name: Optional[str] = None,
resources: Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = None,
cache: Optional[CacheRequest] = None,
retries: Union[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = 0,
timeout: Optional[TimeoutType] = None,
reusable: Union[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), Literal["off"], None] = None,
env_vars: Optional[Dict[str, str]] = None,
secrets: Optional[SecretRequest] = None,
max_inline_io_bytes: int | None = None,
pod_template: Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = None,
queue: Optional[str] = None,
interruptible: Optional[bool] = None,
entrypoint: Optional[bool] = None,
links: Tuple[[Link](../app/types/link.md?sid=flyte_app__types_link), ...] = (),
kwargs: Any
) - > [TaskTemplate](tasktemplate.md?sid=flyte__task_tasktemplate)

Override various parameters of the task template. This allows for dynamic configuration of the task when it is called, such as changing the image, resources, cache policy, etc.

Parameters

NameTypeDescription
short_nameOptional[str] = NoneOptional override for the short name of the task.
resourcesOptional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = NoneOptional override for the resources to use for the task.
cacheOptional[CacheRequest] = NoneOptional override for the cache policy for the task.
retriesUnion[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = 0Optional override for the number of retries for the task.
timeoutOptional[TimeoutType] = NoneOptional override for the timeout for the task.
reusableUnion[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), Literal["off"], None] = NoneOptional override for the reusability policy for the task.
env_varsOptional[Dict[str, str]] = NoneOptional override for the environment variables to set for the task.
secretsOptional[SecretRequest] = NoneOptional override for the secrets that will be injected into the task at runtime.
max_inline_io_bytes`intNone` = None
pod_templateOptional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = NoneOptional override for the pod template to use for the task.
queueOptional[str] = NoneOptional override for the queue to use for the task.
interruptibleOptional[bool] = NoneOptional override for the interruptible policy for the task.
entrypointOptional[bool] = NoneOptional override for the entrypoint flag for the task.
linksTuple[[Link](../app/types/link.md?sid=flyte_app__types_link), ...] = ()Optional override for the Links associated with the task.
kwargsAnyAdditional keyword arguments for further overrides. Some fields like name, image, docs, and interface cannot be overridden.

Returns

TypeDescription
[TaskTemplate](tasktemplate.md?sid=flyte__task_tasktemplate)A new TaskTemplate instance with the overridden parameters.