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
| Attribute | Type | Description |
|---|---|---|
| name | str | The 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_name | str = "" | A shorter name for the task, defaulting to the task's name if not explicitly set. |
| task_type | str = "python" | The router type for the task, used to determine how the task will be executed and typically matches the execution plugin. |
| task_type_version | int = 0 | The version of the task type, used for compatibility and evolution of task definitions. |
| image | `Union[str, Image, Literal["auto"]] | None` = "auto" |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = null | The resources to use for the task, such as CPU and memory allocations. |
| cache | CacheRequest = "disable" | The cache policy for the task; defaults to 'disable', which means task results will not be cached. |
| interruptible | bool = false | The interruptible policy for the task; defaults to False, meaning the task will not be scheduled on interruptible nodes. |
| retries | Union[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = 0 | The number of retries for the task; defaults to 0, meaning no retries will be attempted. |
| reusable | Union[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), None] = null | The reusability policy for the task; defaults to None, meaning the task environment will not be reused across invocations. |
| docs | Optional[Documentation] = null | The documentation for the task; if not provided, the function docstring will be used. |
| env_vars | Optional[Dict[str, str]] = null | The environment variables to set for the task, affecting its execution environment. |
| secrets | Optional[SecretRequest] = null | The secrets that will be injected into the task at runtime, providing secure access to sensitive information. |
| timeout | Optional[TimeoutType] = null | The timeout for the task, after which the task will be terminated if not completed. |
| pod_template | Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = null | The pod template to use for the task, allowing customization of the Kubernetes pod configuration. |
| report | bool = false | Whether to report the task execution to the Flyte console; defaults to False. |
| queue | Optional[str] = null | The queue to use for the task; if not provided, the default queue will be used for scheduling. |
| debuggable | bool = false | Whether the task supports debugging capabilities; defaults to False. |
| entrypoint | bool = false | A boolean indicating if this task is the entrypoint for a workflow. |
| parent_env | Optional[weakref.ReferenceType[[TaskEnvironment](environment/taskenvironment.md?sid=flyte__task_environment_taskenvironment)]] = null | A weak reference to the parent task environment, used to manage task hierarchy and resource sharing. |
| parent_env_name | Optional[str] = null | The name of the parent environment, used for contextual information. |
| ref | bool = false | A boolean flag indicating if this task template is a reference to another task. |
| max_inline_io_bytes | int = MAX_INLINE_IO_BYTES | Maximum allowed size (in bytes) for all inputs and outputs passed directly to the task (e.g., primitives, strings, dicts). |
| triggers | Tuple[[Trigger](../remote/trigger/trigger.md?sid=flyte_remote__trigger_trigger), ...] = tuple | A tuple of Trigger objects that define conditions for task execution. |
| links | Tuple[[Link](../app/types/link.md?sid=flyte_app__types_link), ...] = tuple | A 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
| Name | Type | Description |
|---|---|---|
| name | str = null | Optional The name of the task (defaults to the function name) |
| task_type | str = null | Router 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 |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = null | Optional The resources to use for the task |
| cache | CacheRequest = null | Optional The cache policy for the task, defaults to auto, which will cache the results of the task. |
| interruptible | bool = null | Optional 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. |
| retries | Union[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = null | Optional The number of retries for the task, defaults to 0, which means no retries. |
| reusable | Union[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), None] = null | Optional The reusability policy for the task, defaults to None, which means the task environment will not be reused across task invocations. |
| docs | Optional[Documentation] = null | Optional The documentation for the task, if not provided the function docstring will be used. |
| env_vars | Optional[Dict[str, str]] = null | Optional The environment variables to set for the task. |
| secrets | Optional[SecretRequest] = null | Optional The secrets that will be injected into the task at runtime. |
| timeout | Optional[TimeoutType] = null | Optional The timeout for the task. |
| max_inline_io_bytes | int = null | Maximum 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_template | Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = null | Optional The pod template to use for the task. |
| report | bool = null | Optional Whether to report the task execution to the Flyte console, defaults to False. |
| queue | Optional[str] = null | Optional The queue to use for the task. If not provided, the default queue will be used. |
| debuggable | bool = null | Optional 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
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
| args | Any | Positional arguments passed to the task. |
| kwargs | Any | Keyword arguments passed to the task. |
Returns
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
| args | Any | Positional arguments passed to the task's execution. |
| kwargs | Any | Keyword arguments passed to the task's execution. |
Returns
| Type | Description |
|---|---|
Any | The 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
| Name | Type | Description |
|---|---|---|
| return_vals | Any | The values returned by the task's execute method. |
Returns
| Type | Description |
|---|---|
Any | The 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
| Name | Type | Description |
|---|---|---|
| sctx | [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext) | The serialization context, providing information for serialization. |
Returns
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
| sctx | [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext) | The serialization context, providing information for serialization. |
Returns
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
| sctx | [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext) | The serialization context, providing information for serialization. |
Returns
| Type | Description |
|---|---|
DataLoadingConfig | The 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
| Name | Type | Description |
|---|---|---|
| sctx | [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext) | The serialization context, providing information for serialization. |
Returns
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
| sctx | [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext) | The serialization context, providing information for serialization. |
Returns
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
[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
| Name | Type | Description |
|---|---|---|
| args | P.args | Positional arguments to pass to the underlying task. |
| kwargs | P.kwargs | Keyword arguments to pass to the underlying task. |
Returns
| Type | Description |
|---|---|
| `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
| Name | Type | Description |
|---|---|---|
| args | P.args | Positional arguments to pass to the task. |
| kwargs | P.kwargs | Keyword arguments to pass to the task. |
Returns
| Type | Description |
|---|---|
| `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
| Name | Type | Description |
|---|---|---|
| short_name | Optional[str] = None | Optional override for the short name of the task. |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = None | Optional override for the resources to use for the task. |
| cache | Optional[CacheRequest] = None | Optional override for the cache policy for the task. |
| retries | Union[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = 0 | Optional override for the number of retries for the task. |
| timeout | Optional[TimeoutType] = None | Optional override for the timeout for the task. |
| reusable | Union[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), Literal["off"], None] = None | Optional override for the reusability policy for the task. |
| env_vars | Optional[Dict[str, str]] = None | Optional override for the environment variables to set for the task. |
| secrets | Optional[SecretRequest] = None | Optional override for the secrets that will be injected into the task at runtime. |
| max_inline_io_bytes | `int | None` = None |
| pod_template | Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = None | Optional override for the pod template to use for the task. |
| queue | Optional[str] = None | Optional override for the queue to use for the task. |
| interruptible | Optional[bool] = None | Optional override for the interruptible policy for the task. |
| entrypoint | Optional[bool] = None | Optional override for the entrypoint flag for the task. |
| links | Tuple[[Link](../app/types/link.md?sid=flyte_app__types_link), ...] = () | Optional override for the Links associated with the task. |
| kwargs | Any | Additional keyword arguments for further overrides. Some fields like name, image, docs, and interface cannot be overridden. |
Returns
| Type | Description |
|---|---|
[TaskTemplate](tasktemplate.md?sid=flyte__task_tasktemplate) | A new TaskTemplate instance with the overridden parameters. |