TaskContext
A context class to hold the current task executions context. This can be used to access various contextual parameters in the task execution by the user.
Attributes
| Attribute | Type | Description |
|---|---|---|
| action | [ActionID](actionid.md?sid=flyte_models_actionid) | The action ID of the current execution, which is always set within a run. |
| version | str | The version of the executed task, set when the task is executed by an action and propagated to all sub-actions. |
| raw_data_path | [RawDataPath](rawdatapath.md?sid=flyte_models_rawdatapath) | The path to raw data used by the task. |
| input_path | `str | None` = None |
| output_path | str | The path where the task's output data will be stored. |
| run_base_dir | str | The base directory for the current task run. |
| report | [Report](../report/report/report.md?sid=flyte_report__report_report) | An object for generating reports related to the task execution. |
| group_data | `GroupData | None` = None |
| checkpoint_paths | `CheckpointPaths | None` = None |
| code_bundle | `CodeBundle | None` = None |
| compiled_image_cache | `ImageCache | None` = None |
| data | Dict[str, Any] = {} | A dictionary to store arbitrary key-value data for the task context. |
| mode | Literal["local", "remote", "hybrid"] = remote | The execution mode of the task, which can be 'local', 'remote', or 'hybrid'. |
| interactive_mode | bool = false | A boolean indicating if the task is running in interactive mode. |
| custom_context | Dict[str, str] = {} | Context metadata for the action, which is automatically passed to any spawned actions but not used for cache key computation. |
| disable_run_cache | bool = false | A boolean flag to disable the run cache for the current task execution. |
| in_driver_literal_conversion | bool = false | True while converting literals for nested-task / driver orchestration (not task-body I/O), indicating that type transformers should omit non-essential side effects (e.g. duplicate HTML tabs) when set. |
Methods
replace()
@classmethod
def replace(
kwargs: **kwargs
) - > [TaskContext](taskcontext.md?sid=flyte_models_taskcontext)
Replaces or updates attributes of the TaskContext instance. If 'data' is provided, it merges the new data with the existing data.
Parameters
| Name | Type | Description |
|---|---|---|
| kwargs | **kwargs | Keyword arguments representing the attributes to replace or update in the TaskContext. If 'data' is included, its values are merged with the existing 'data' dictionary. |
Returns
| Type | Description |
|---|---|
[TaskContext](taskcontext.md?sid=flyte_models_taskcontext) | A new TaskContext instance with the specified attributes replaced or updated. |
is_in_cluster()
@classmethod
def is_in_cluster() - > bool
Check if the task is running in a cluster.
Returns
| Type | Description |
|---|---|
bool | True if the task's mode is 'remote', indicating it is running in a cluster; otherwise, False. |
checkpoint()
@classmethod
def checkpoint() - > Optional[[Checkpoint](../checkpoint/checkpoint.md?sid=flyte__checkpoint_checkpoint)]
Task checkpoint helper for the runtime checkpoint_path / prev_checkpoint prefixes. Returns a lazily constructed flyte.Checkpoint cached on flyte.models.TaskContext.data, or None when no checkpoint output prefix is configured. In async tasks use flyte.Checkpoint.load and flyte.Checkpoint.save; in sync tasks use flyte.Checkpoint.load_sync and flyte.Checkpoint.save_sync. For a single raw blob, pass bytes to save; after a successful load, the blob is at checkpoint.path / "payload" when the remote object is not a tarball.
Returns
| Type | Description |
|---|---|
Optional[[Checkpoint](../checkpoint/checkpoint.md?sid=flyte__checkpoint_checkpoint)] | A Checkpoint object if checkpoint paths are configured, otherwise None. |
attempt_number()
@classmethod
def attempt_number() - > int
Get the attempt number for the current task.
Returns
| Type | Description |
|---|---|
int | The attempt number, retrieved from the 'FLYTE_ATTEMPT_NUMBER' environment variable, defaulting to 0 if not set. |