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. This is always set, within a run. |
| version | str | The version of the executed task. This is set when the task is executed by an action and will be set on all sub-actions. |
| raw_data_path | [RawDataPath](rawdatapath.md?sid=flyte_models_rawdatapath) | The path to the raw data storage location for the current task execution. |
| input_path | `str | None` = null |
| output_path | str | The file path or URI where the task's output data should be written. |
| run_base_dir | str | The base directory on the local file system for the current task run. |
| report | [Report](../report/report/report.md?sid=flyte_report__report_report) | The report object used to log or visualize task execution details. |
| group_data | `GroupData | None` = null |
| checkpoint_paths | `CheckpointPaths | None` = null |
| code_bundle | `CodeBundle | None` = null |
| compiled_image_cache | `ImageCache | None` = null |
| data | Dict[str, Any] = {} | A dictionary for storing arbitrary execution data and cached objects like checkpoints. |
| mode | Literal["local", "remote", "hybrid"] = "remote" | The execution environment mode, which can be local, remote, or hybrid. |
| interactive_mode | bool = false | A flag indicating whether the task is running in an interactive session. |
| custom_context | Dict[str, str] = {} | Context metadata for the action. If an action receives context, it'll automatically pass it to any actions it spawns. |
| disable_run_cache | bool = false | A flag to explicitly disable caching for the current task execution. |
| in_driver_literal_conversion | bool = false | Set by the runtime during nested-task literal marshalling; type transformers may use it to skip duplicate side effects (e.g. report tabs) outside true task-body I/O. |
Constructor
Signature
def TaskContext(
action: [ActionID](actionid.md?sid=flyte_models_actionid),
version: str,
raw_data_path: [RawDataPath](rawdatapath.md?sid=flyte_models_rawdatapath),
input_path: str | None = None,
output_path: str,
run_base_dir: str,
report: [Report](../report/report/report.md?sid=flyte_report__report_report),
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] = field(default_factory=dict),
mode: Literal['local', 'remote', 'hybrid'] = remote,
interactive_mode: bool = False,
custom_context: Dict[str, str] = field(default_factory=dict),
disable_run_cache: bool = False,
in_driver_literal_conversion: bool = False
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| action | [ActionID](actionid.md?sid=flyte_models_actionid) | The action ID of the current execution. |
| version | str | The version of the executed task. |
| raw_data_path | [RawDataPath](rawdatapath.md?sid=flyte_models_rawdatapath) | The path for raw data storage. |
| input_path | `str | None` = None |
| output_path | str | The path where task outputs should be stored. |
| run_base_dir | str | The base directory for the current run. |
| report | [Report](../report/report/report.md?sid=flyte_report__report_report) | The report object for the task. |
| 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] = field(default_factory=dict) | A dictionary for storing arbitrary contextual data. |
| mode | Literal['local', 'remote', 'hybrid'] = remote | The execution mode of the task. |
| interactive_mode | bool = False | Whether the task is running in interactive mode. |
| custom_context | Dict[str, str] = field(default_factory=dict) | Context metadata for the action passed to sub-actions. |
| disable_run_cache | bool = False | Whether to disable the run cache for this task. |
| in_driver_literal_conversion | bool = False | Flag indicating if the runtime is performing nested-task literal marshalling. |
Methods
replace()
@classmethod
def replace(
**kwargs: Any
) - > [TaskContext](taskcontext.md?sid=flyte_models_taskcontext)
Creates a new TaskContext instance with updated attributes, merging the provided data dictionary with existing context data.
Parameters
| Name | Type | Description |
|---|---|---|
| **kwargs | Any | Key-value pairs representing the TaskContext attributes to update, such as 'data', 'mode', or 'custom_context'. |
Returns
| Type | Description |
|---|---|
[TaskContext](taskcontext.md?sid=flyte_models_taskcontext) | A new TaskContext instance containing the updated configuration and merged data. |
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 execution mode is 'remote', indicating it is running within a cluster environment. |
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
| Type | Description |
|---|---|
Optional[[Checkpoint](../checkpoint/checkpoint.md?sid=flyte__checkpoint_checkpoint)] | A lazily constructed Checkpoint object for managing state persistence, or None if no checkpoint path is configured. |
attempt_number()
@classmethod
def attempt_number() - > int
Get the attempt number for the current task.
Returns
| Type | Description |
|---|---|
int | The integer representation of the current task execution attempt, sourced from environment variables. |