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) | Defines the input and output types for the task to ensure type safety during execution. |
| short_name | str | Optional override for the short name of the task, defaulting to the task name if not provided. |
| task_type | str = python | Router type for the task, this is used to determine how the task will be executed. |
| task_type_version | int = 0 | Version number of the task type used for compatibility and plugin routing. |
| 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 |
| cache | CacheRequest = disable | The cache policy for the task, defaults to auto, which will cache the results of the task. |
| interruptible | bool = false | The interruptible policy for the task, defaults to False, which means 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, which means no retries. |
| reusable | Union[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), None] = null | 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 | 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. |
| secrets | Optional[SecretRequest] = null | The secrets that will be injected into the task at runtime. |
| timeout | Optional[TimeoutType] = null | The timeout for the task. |
| pod_template | Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = null | The pod template to use for the task. |
| 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. |
| debuggable | bool = false | Whether the task supports debugging capabilities, defaults to False. |
| entrypoint | bool = false | Flag indicating whether this task serves as the primary entrypoint for execution. |
| parent_env | Optional[weakref.ReferenceType[[TaskEnvironment](environment/taskenvironment.md?sid=flyte__task_environment_taskenvironment)]] = null | A weak reference to the environment that created the task, used to avoid circular references during pickling. |
| parent_env_name | Optional[str] = null | The name of the parent environment associated with this task template. |
| ref | bool = false | Internal flag used to determine if the task 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), ...] = () | A collection of triggers that define when the task should be automatically executed. |
| links | Tuple[[Link](../app/types/link.md?sid=flyte_app__types_link), ...] = () | A collection of external links associated with the task for documentation or tracking purposes. |
Constructor
Signature
def TaskTemplate(
name: str,
interface: [NativeInterface](../models/nativeinterface.md?sid=flyte_models_nativeinterface),
short_name: str = "",
task_type: str = "python",
image: Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"]] = "auto",
resources: Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = null,
cache: CacheRequest = "disable",
interruptible: bool = false,
retries: Union[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = 0,
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,
pod_template: Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = null,
report: bool = false,
queue: Optional[str] = null,
debuggable: bool = false,
max_inline_io_bytes: int = MAX_INLINE_IO_BYTES
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The name of the task (defaults to the function name). |
| interface | [NativeInterface](../models/nativeinterface.md?sid=flyte_models_nativeinterface) | The interface defining inputs and outputs of the task. |
| short_name | str = "" | A shorter identifier for the task. |
| task_type | str = "python" | Router type used to determine the execution plugin. |
| image | Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"]] = "auto" | The container image to use for the task. |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = null | The compute resources (CPU, memory, etc.) required. |
| cache | CacheRequest = "disable" | The cache policy for the task results. |
| interruptible | bool = false | Whether the task can be scheduled on interruptible nodes. |
| retries | Union[int, [RetryStrategy](../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] = 0 | The number of retries or retry strategy for the task. |
| reusable | Union[[ReusePolicy](../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy), None] = null | Policy for environment reusability across invocations. |
| docs | Optional[Documentation] = null | Documentation for the task. |
| env_vars | Optional[Dict[str, str]] = null | Environment variables to set for the task. |
| secrets | Optional[SecretRequest] = null | Secrets to be injected at runtime. |
| timeout | Optional[TimeoutType] = null | The maximum execution time for the task. |
| pod_template | Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = null | The pod template to use for the task. |
| report | bool = false | Whether to report execution to the Flyte console. |
| queue | Optional[str] = null | The specific queue to use for task execution. |
| debuggable | bool = false | Whether the task supports debugging capabilities. |
| max_inline_io_bytes | int = MAX_INLINE_IO_BYTES | Maximum size for inputs/outputs passed directly. |
Methods
source_file()
@classmethod
def source_file() - > str | null
Retrieves the path to the source file where the task is defined.
Returns
| Type | Description |
|---|---|
| `str | null` |
pre()
@classmethod
def pre(
args: Any,
kwargs: Any
) - > dict
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 | A dictionary of values to be used during task execution |
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 for the task logic |
| kwargs | Any | Keyword arguments for the task logic |
Returns
| Type | Description |
|---|---|
Any | The result of the task 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 raw output produced by the execute method |
Returns
| Type | Description |
|---|---|
Any | The processed return values |
config()
@classmethod
def config(
sctx: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > dict
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 context used to manage serialization state |
Returns
| Type | Description |
|---|---|
dict | A dictionary of configuration keys and values |
custom_config()
@classmethod
def custom_config(
sctx: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > dict
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 context used to manage serialization state |
Returns
| Type | Description |
|---|---|
dict | A dictionary of plugin-specific configuration settings |
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
Parameters
| Name | Type | Description |
|---|---|---|
| sctx | [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext) | The context used to manage serialization state |
Returns
| Type | Description |
|---|---|
DataLoadingConfig | The configuration defining how inputs and outputs are side-loaded |
container_args()
@classmethod
def container_args(
sctx: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > list
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 context used to manage serialization state |
Returns
| Type | Description |
|---|---|
list | A list of command-line arguments for the container |
sql()
@classmethod
def sql(
sctx: [SerializationContext](../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > str | null
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 context used to manage serialization state |
Returns
| Type | Description |
|---|---|
| `str | null` |
native_interface()
@classmethod
def native_interface() - > [NativeInterface](../models/nativeinterface.md?sid=flyte_models_nativeinterface)
Provides access to the native interface definition of the task.
Returns
| Type | Description |
|---|---|
[NativeInterface](../models/nativeinterface.md?sid=flyte_models_nativeinterface) | The interface object defining inputs and outputs |
aio()
@classmethod
def aio(
args: Any,
kwargs: Any
) - > Coroutine | Any
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.
Parameters
| Name | Type | Description |
|---|---|---|
| args | Any | Positional arguments for the task |
| kwargs | Any | Keyword arguments for the task |
Returns
| Type | Description |
|---|---|
| `Coroutine | Any` |
forward()
@classmethod
def forward(
args: Any,
kwargs: Any
) - > Coroutine | Any
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.
Parameters
| Name | Type | Description |
|---|---|---|
| args | Any | Arguments for local execution |
| kwargs | Any | Keyword arguments for local execution |
Returns
| Type | Description |
|---|---|
| `Coroutine | Any` |
override()
@classmethod
def override(
short_name: str | null,
resources: Resources | null,
cache: CacheRequest | null,
retries: int | RetryStrategy,
timeout: TimeoutType | null,
reusable: ReusePolicy | str | null,
env_vars: dict | null,
secrets: SecretRequest | null,
max_inline_io_bytes: int | null,
pod_template: str | PodTemplate | null,
queue: str | null,
interruptible: bool | null,
entrypoint: bool | null,
links: tuple
) - > [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 | `str | null` |
| resources | `Resources | null` |
| cache | `CacheRequest | null` |
| retries | `int | RetryStrategy` |
| timeout | `TimeoutType | null` |
| reusable | `ReusePolicy | str |
| env_vars | `dict | null` |
| secrets | `SecretRequest | null` |
| max_inline_io_bytes | `int | null` |
| pod_template | `str | PodTemplate |
| queue | `str | null` |
| interruptible | `bool | null` |
| entrypoint | `bool | null` |
| links | tuple | Optional override for external links associated with the task |
Returns
| Type | Description |
|---|---|
[TaskTemplate](tasktemplate.md?sid=flyte__task_tasktemplate) | A new TaskTemplate instance with the overridden parameters |