Skip to main content

TaskEnvironment

Define an execution environment for a set of tasks.

Attributes

AttributeTypeDescription
cacheCacheRequest = "disable"Cache policy — "auto", "override", "disable", or a Cache object.
reusable`ReusePolicyNone` = null
plugin_configOptional[Any] = nullPlugin configuration for custom task types (e.g., Ray, Spark).
queueOptional[str] = nullQueue 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

NameTypeDescription
namestrName of the environment (required). Must be snake_case or kebab-case.
imageUnion[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_onOptional[List[[Environment](../../environment/environment.md?sid=flyte__environment_environment)]]List of other environments this one depends on for deployment.
descriptionOptional[str]Human-readable description (max 255 characters).
plugin_configOptional[Any]Plugin configuration for custom task types (e.g., Ray, Spark). Cannot be combined with reusable.
resourcesOptional[[Resources](../../resources/resources.md?sid=flyte__resources_resources)]Compute resources (CPU, memory, GPU, disk).
env_varsOptional[dict[str, str]]Environment variables as a dictionary.
secretsOptional[SecretRequest]Secrets to inject into the environment.
cacheCacheRequest = disableCache policy — 'auto', 'override', 'disable', or a Cache object.
reusableOptional[[ReusePolicy](../../reusable/environment/reusepolicy.md?sid=flyte__reusable_environment_reusepolicy)] = NoneReusePolicy for container reuse.
queueOptional[str] = NoneQueue name for scheduling on specific infrastructure partitions.
pod_templateOptional[Union[str, [PodTemplate](../../pod/podtemplate.md?sid=flyte__pod_podtemplate)]]Kubernetes pod template for advanced configuration (sidecars, volumes, etc.).
interruptibleOptional[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

NameTypeDescription
namestrThe unique identifier for the new environment.
imageOptional[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.
resourcesOptional[[Resources](../../resources/resources.md?sid=flyte__resources_resources)]The compute resource requirements (CPU, memory, GPU) for tasks in the new environment.
env_varsOptional[Dict[str, str]]A dictionary of environment variables to be injected into the task containers.
secretsOptional[SecretRequest]The secret requests defining sensitive data access for the environment.
depends_onOptional[List[[Environment](../../environment/environment.md?sid=flyte__environment_environment)]]A list of environment dependencies required for deployment.
descriptionOptional[str]A human-readable summary of the environment's purpose.
interruptibleOptional[bool]Whether tasks in this environment should prefer spot or preemptible instances.
includeOptional[Tuple[str, ...]]A tuple of specific components or modules to include in the cloned environment.

Returns

TypeDescription
[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

NameTypeDescription
_funcCallableThe function to decorate. If not provided, the decorator will return a callable that accepts a function to be decorated.
short_nameOptional[str]Friendly name for the task or action used in the UI; defaults to the function name.
cache`CacheRequestNone`
retriesUnion[int, [RetryStrategy](../../retry/retrystrategy.md?sid=flyte__retry_retrystrategy)]The number of retry attempts or a specific strategy for handling task failures.
timeoutUnion[timedelta, int]The maximum duration the task is allowed to run before being terminated.
docsOptional[Documentation]Documentation object for the task; defaults to the function's docstring if not provided.
pod_templateOptional[Union[str, [PodTemplate](../../pod/podtemplate.md?sid=flyte__pod_podtemplate)]]The Kubernetes pod template used for advanced container configuration.
reportboolWhether to generate an HTML report for the task execution.
interruptible`boolNone`
max_inline_io_bytesintThe size limit for inputs and outputs passed directly rather than via offloaded storage.
queueOptional[str]The specific execution queue or cluster partition where this task should be scheduled.
triggers`Tuple[Trigger, ...]Trigger`
links`Tuple[Link, ...]Link`
task_resolver`AnyNone`
entrypointboolFlags the task as a primary entrypoint for the UI.

Returns

TypeDescription
[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

TypeDescription
_SandboxNamespaceA 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

TypeDescription
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

NameTypeDescription
namestrThe 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_onOptional[List[[Environment](../../environment/environment.md?sid=flyte__environment_environment)]]Optional list of environments that this environment depends on for deployment.

Returns

TypeDescription
[TaskEnvironment](taskenvironment.md?sid=flyte__task_environment_taskenvironment)A new TaskEnvironment instance containing the provided tasks.