TaskEnvironment
Define an execution environment for a set of tasks.
Attributes
| Attribute | Type | Description |
|---|---|---|
| cache | CacheRequest = "disable" | Cache policy — "auto", "override", "disable", or a Cache object. |
| reusable | `ReusePolicy | None` = null |
| plugin_config | Optional[Any] = null | Plugin configuration for custom task types (e.g., Ray, Spark). |
| queue | Optional[str] = null | Queue name for scheduling. Queues identify specific partitions of your compute infrastructure (e.g., a particular cluster in a multi-cluster deployment) and are configured as part of your Flyte/Union deployment. |
Constructor
Signature
def TaskEnvironment(
name: str,
image: Union[str, [Image](../../image/image.md?sid=flyte__image_image), Literal['auto']],
depends_on: Optional[List[[Environment](../../environment/environment.md?sid=flyte__environment_environment)]],
description: Optional[str],
plugin_config: Optional[Any],
resources: Optional[[Resources](../../resources/resources.md?sid=flyte__resources_resources)],
env_vars: Optional[dict[str, str]],
secrets: Optional[SecretRequest],
cache: CacheRequest = disable,
reusable: Optional[[ReusePolicy](../../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy)] = None,
queue: Optional[str] = None,
pod_template: Optional[Union[str, [PodTemplate](../../pod/podtemplate.md?sid=flyte__pod_podtemplate)]],
interruptible: Optional[bool]
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | Name of the environment (required). Must be snake_case or kebab-case. |
| image | Union[str, [Image](../../image/image.md?sid=flyte__image_image), Literal['auto']] | Docker image for the environment. Can be a string (image URI), an Image object, or 'auto' to use the default image. |
| depends_on | Optional[List[[Environment](../../environment/environment.md?sid=flyte__environment_environment)]] | List of other environments this one depends on for deployment. |
| description | Optional[str] | Human-readable description (max 255 characters). |
| plugin_config | Optional[Any] | Plugin configuration for custom task types (e.g., Ray, Spark). Cannot be combined with reusable. |
| resources | Optional[[Resources](../../resources/resources.md?sid=flyte__resources_resources)] | Compute resources (CPU, memory, GPU, disk). |
| env_vars | Optional[dict[str, str]] | Environment variables as a dictionary. |
| secrets | Optional[SecretRequest] | Secrets to inject into the environment. |
| cache | CacheRequest = disable | Cache policy — 'auto', 'override', 'disable', or a Cache object. |
| reusable | Optional[[ReusePolicy](../../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy)] = None | ReusePolicy for container reuse. |
| queue | Optional[str] = None | Queue name for scheduling on specific infrastructure partitions. |
| pod_template | Optional[Union[str, [PodTemplate](../../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] | Kubernetes pod template for advanced configuration (sidecars, volumes, etc.). |
| interruptible | Optional[bool] | Whether tasks can run on spot/preemptible instances. |
Methods
clone_with()
@classmethod
def clone_with(
name: str,
image: Optional[Union[str, [Image](../../image/image.md?sid=flyte__image_image), Literal["auto"]]],
resources: Optional[[Resources](../../resources/resources.md?sid=flyte__resources_resources)],
env_vars: Optional[Dict[str, str]],
secrets: Optional[SecretRequest],
depends_on: Optional[List[[Environment](../../environment/environment.md?sid=flyte__environment_environment)]],
description: Optional[str],
interruptible: Optional[bool],
include: Optional[Tuple[str, ...]]
) - > [TaskEnvironment](taskenvironment.md?sid=flyte__task_environment_taskenvironment)
Create a new TaskEnvironment that shares most settings with this one but differs in name and selected overrides.
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The unique identifier for the new environment. |
| image | Optional[Union[str, [Image](../../image/image.md?sid=flyte__image_image), Literal["auto"]]] | The container image URI, Image object, or "auto" keyword to override the base image. |
| resources | Optional[[Resources](../../resources/resources.md?sid=flyte__resources_resources)] | The compute resource requirements (CPU, memory, GPU) for tasks in the new environment. |
| env_vars | Optional[Dict[str, str]] | A dictionary of environment variables to be injected into the task containers. |
| secrets | Optional[SecretRequest] | The secret requests defining sensitive data access for the environment. |
| depends_on | Optional[List[[Environment](../../environment/environment.md?sid=flyte__environment_environment)]] | A list of environment dependencies required for deployment. |
| description | Optional[str] | A human-readable summary of the environment's purpose. |
| interruptible | Optional[bool] | Whether tasks in this environment should prefer spot or preemptible instances. |
| include | Optional[Tuple[str, ...]] | A tuple of specific components or modules to include in the cloned environment. |
Returns
| Type | Description |
|---|---|
[TaskEnvironment](taskenvironment.md?sid=flyte__task_environment_taskenvironment) | A new TaskEnvironment instance with the specified overrides applied. |
task()
@classmethod
def task(
_func: Callable,
short_name: Optional[str],
cache: CacheRequest | None,
retries: Union[int, [RetryStrategy](../../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)],
timeout: Union[timedelta, int],
docs: Optional[Documentation],
pod_template: Optional[Union[str, [PodTemplate](../../pod/podtemplate.md?sid=flyte__pod_podtemplate)]],
report: bool,
interruptible: bool | None,
max_inline_io_bytes: int,
queue: Optional[str],
triggers: Tuple[[Trigger](../../remote/trigger/trigger.md?sid=flyte_remote__trigger_trigger), ...]| Trigger,
links: Tuple[[Link](../../app/types/link.md?sid=flyte_app__types_link), ...]| Link,
task_resolver: Any | None,
entrypoint: bool
) - > [AsyncFunctionTaskTemplate](../asyncfunctiontasktemplate.md?sid=flyte__task_asyncfunctiontasktemplate)
Decorate a function to be a task.
Parameters
| Name | Type | Description |
|---|---|---|
| _func | Callable | The function to decorate. If not provided, the decorator will return a callable that accepts a function to be decorated. |
| short_name | Optional[str] | Friendly name for the task or action used in the UI; defaults to the function name. |
| cache | `CacheRequest | None` |
| retries | Union[int, [RetryStrategy](../../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)] | The number of retry attempts or a specific strategy for handling task failures. |
| timeout | Union[timedelta, int] | The maximum duration the task is allowed to run before being terminated. |
| docs | Optional[Documentation] | Documentation object for the task; defaults to the function's docstring if not provided. |
| pod_template | Optional[Union[str, [PodTemplate](../../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] | The Kubernetes pod template used for advanced container configuration. |
| report | bool | Whether to generate an HTML report for the task execution. |
| interruptible | `bool | None` |
| max_inline_io_bytes | int | The size limit for inputs and outputs passed directly rather than via offloaded storage. |
| queue | Optional[str] | The specific execution queue or cluster partition where this task should be scheduled. |
| triggers | `Tuple[Trigger, ...] | Trigger` |
| links | `Tuple[Link, ...] | Link` |
| task_resolver | `Any | None` |
| entrypoint | bool | Flags the task as a primary entrypoint for the UI. |
Returns
| Type | Description |
|---|---|
[AsyncFunctionTaskTemplate](../asyncfunctiontasktemplate.md?sid=flyte__task_asyncfunctiontasktemplate) | A TaskTemplate that can be used to deploy the task. |
sandbox()
@classmethod
def sandbox() - > _SandboxNamespace
Access the sandbox namespace for creating sandboxed tasks.
Returns
| Type | Description |
|---|---|
_SandboxNamespace | A namespace object used to define tasks within a restricted sandbox environment. |
tasks()
@classmethod
def tasks() - > Dict[str, [TaskTemplate](../tasktemplate.md?sid=flyte__task_tasktemplate)]
Get all tasks defined in the environment.
Returns
| Type | Description |
|---|---|
Dict[str, [TaskTemplate](../tasktemplate.md?sid=flyte__task_tasktemplate)] | A mapping of fully-qualified task names to their respective TaskTemplate objects. |
from_task()
@classmethod
def from_task(
name: str,
tasks: [TaskTemplate](../tasktemplate.md?sid=flyte__task_tasktemplate),
depends_on: Optional[List[[Environment](../../environment/environment.md?sid=flyte__environment_environment)]]
) - > [TaskEnvironment](taskenvironment.md?sid=flyte__task_environment_taskenvironment)
Create a TaskEnvironment from a list of tasks. All tasks should have the same image or no Image defined.
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The name of the new environment to be created. |
| tasks | [TaskTemplate](../tasktemplate.md?sid=flyte__task_tasktemplate) | A variable number of task templates to group into the new environment. |
| depends_on | Optional[List[[Environment](../../environment/environment.md?sid=flyte__environment_environment)]] | Optional list of environments that this environment depends on for deployment. |
Returns
| Type | Description |
|---|---|
[TaskEnvironment](taskenvironment.md?sid=flyte__task_environment_taskenvironment) | A new TaskEnvironment instance containing the provided tasks. |