Flytekit
Flytekit is the Python SDK for Flyte, an open-source platform for building highly scalable, reliable, and reproducible data and ML workflows. It allows developers to author tasks, workflows, and launch plans using familiar Pythonic constructs like functions and decorators. Currently at version 1.16.19, Flytekit maintains a rapid release cadence with multiple minor updates typically published each month.
Warnings
- breaking Flytekit v1.14.0 introduced a change to use MessagePack for serializing Python `dict`, `dataclass`, and `Pydantic BaseModel` types instead of JSON strings within a Protobuf struct. This change is not fully backward-compatible with Flyte backend versions older than 1.14. If referencing tasks registered with `flytekit>=1.14` from downstream tasks using `flytekit<1.14`, you may encounter `TypeTransformerFailedError`.
- breaking When upgrading to `flytekit>=1.13.0`, users have reported `TaskReferenceNotFound` errors during workflow compilation and registration, especially when registering scripts to a Flyte cluster. Older versions (e.g., `flytekit==1.11.0`) might not exhibit this behavior.
- gotcha Flytekit strictly enforces type hints for all task inputs and outputs. If type annotations are incorrect or missing (and cannot be inferred), Flytekit will raise a compilation error during registration, preventing the workflow from running. This is a design choice to ensure robust and predictable workflows.
- gotcha The body of a `@workflow` decorated function in Flytekit executes at *registration time* to construct the Directed Acyclic Graph (DAG) of tasks, not at runtime for actual computation. The actual computation logic is encapsulated within individual `@task` decorated functions.
- gotcha Flytekit's current stable versions (1.16.x) explicitly support Python versions 3.10, 3.11, and 3.12. Older Python versions, such as 3.8 or 3.9, may not be fully supported or tested, and could lead to unexpected behavior or installation issues.
- gotcha In dynamic workflows, if one subtask fails, the default behavior is for all other running subtasks within that dynamic workflow to also fail. This is designed to conserve resources, assuming downstream tasks depend on all upstream outputs.
Install
-
pip install flytekit
Imports
- task
from flytekit import task
- workflow
from flytekit import workflow
- current_context
from flytekit import current_context
Quickstart
from flytekit import task, workflow
@task
def say_hello(name: str) -> str:
return f"Hello, {name}!"
@workflow
def hello_world_wf(name: str = "world") -> str:
res = say_hello(name=name)
return res
if __name__ == "__main__":
# Run locally
print(f"Local execution: {hello_world_wf(name='Flyte')}")
# Alternatively, use pyflyte CLI for local or remote execution:
# pyflyte run your_script.py hello_world_wf --name Flyte