A task is the fundamental building block and an extension point within Flyte. Tasks have the following characteristics:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/flyteorg/flyte/llms.txt
Use this file to discover all available pages before exploring further.
- Versioned — typically aligned with the git SHA
- Strongly typed — all inputs and outputs must be annotated
- Declarative — describe what the task does, not how to schedule it
- Independently executable — a task can be run on its own without a workflow
- Unit-testable — call task functions directly in tests
Basic task
Apply the@task decorator to any Python function. All inputs and outputs must have type annotations:
task.py
When calling a task function, always use keyword arguments. Positional arguments are not supported.
Run a task with pyflyte
- Local
- Remote
Multiple outputs
Return atuple when a task produces multiple outputs. Flyte assigns default names o0, o1, o2, … in positional order:
Resource requests
UseResources to request CPU, memory, or GPU for a task:
requests describes the minimum resources Kubernetes should reserve. Use limits to cap the maximum. Both accept the same Resources fields.Caching
Enable caching to skip re-execution when inputs have not changed. Setcache=True and provide a cache_version string:
Retries
Configure automatic retries for tasks that may fail transiently (e.g., network calls):Timeouts
Set a maximum execution time for a task usingtimeout:
Environment variables
Pass environment variables into the task container usingenvironment:
Combining task options
All task options can be combined on a single decorator:Task types
Python function task
Python function task
The most common type. Apply
@task to any Python function. Runs the function body in a container on Kubernetes.Shell task
Shell task
Run bash scripts using
ShellTask. See Shell tasks for a full guide.Plugin tasks
Plugin tasks
Flyte supports backend plugins for services like AWS Athena, Google BigQuery, SageMaker, Spark, and Ray. These extend the
@task interface without requiring custom container code.Next steps
Workflows
Connect tasks together into a directed acyclic graph.
Named outputs
Assign meaningful names to task outputs using NamedTuple.