Hera Workflows
Hera Workflows is a Python library that simplifies the orchestration of Python code on Argo Workflows. It allows users to define, construct, and submit complex workflows entirely in Python, abstracting away much of the underlying YAML complexity. The current version is 6.0.0, and the project maintains an active release cadence with frequent updates.
Common errors
-
ModuleNotFoundError: No module named 'pydantic.v1'
cause Upgrading to Hera Workflows v6.0.0+ without updating Pydantic or having other libraries that still implicitly require Pydantic v1. Hera v6+ requires Pydantic v2.fixEnsure Pydantic v2 is installed (`pip install 'pydantic>=2'`) and check for other dependencies that might be pinning Pydantic v1. -
TypeError: 'function' object is not callable
cause Attempting to use `@workflow` or `@task` decorators after upgrading to Hera Workflows v6.0.0, where they have been removed.fixRemove the decorators and instantiate `Workflow` and `Task` classes directly. For example, replace `@task` with `Task(func=your_function, ...)`, and `@workflow` with `with Workflow(...) as w:`. -
AttributeError: type object 'Field' has no attribute 'Required'
cause This typically indicates a mismatch between Pydantic v1 and v2 usage, often when Hera v6+ is used with existing code expecting Pydantic v1 Field behavior.fixThis error means Pydantic V1 is being used where Pydantic V2 is expected or vice-versa. Ensure all Pydantic-related code (including third-party libraries) is compatible with the version Hera (V2) expects. Hera's core models are now dataclasses, so this is usually in user-defined I/O models. -
ERROR: Package 'hera-workflows' requires a different Python version: <4, >=3.10 but your Python version is X.Y
cause Attempting to install or run Hera Workflows v5.27.0+ on an unsupported Python version (e.g., Python 3.9).fixUpgrade your Python environment to 3.10 or higher. Hera Workflows v5.27.0+ requires Python >=3.10.
Warnings
- breaking Hera Workflows v6.0.0 has removed the decorator feature (e.g., `@workflow`, `@task`). Workflows and tasks must now be defined by directly instantiating the `Workflow` and `Task` classes.
- breaking Hera Workflows v6.0.0 has migrated its core models away from Pydantic V1 to Python dataclasses, and now requires Pydantic V2 for any remaining Pydantic integrations. Code relying on Pydantic V1 behavior or direct manipulation of Hera models as Pydantic V1 objects will break.
- breaking Support for Python 3.9 was removed in Hera Workflows v5.27.0.
- gotcha Submitting a workflow requires access to an Argo Workflows API server. Configuration is typically handled via `hera.shared.global_config` or by passing a `hera.workflows.service.Services` instance to the `Workflow` constructor. Incorrect configuration leads to connection errors.
- gotcha The `script` helper function, used for wrapping Python functions to run as Argo script templates, moved from `hera.workflows` to `hera.shared` in Hera Workflows v5.x.
Install
-
pip install hera-workflows
Imports
- Workflow
from hera.workflows import Workflow
- Task
from hera.workflows import Task
- Parameter
from hera.workflows import Parameter
- Artifact
from hera.workflows import Artifact
- script
from hera.workflows import script
from hera.shared import script
Quickstart
import os
from hera.workflows import Workflow, Task, Parameter
from hera.shared import global_config
# Configure Hera to connect to Argo Workflows (adjust as needed)
# For local testing, ensure ARGO_SERVER and ARGO_TOKEN are set,
# or modify client configuration directly.
global_config.host = os.environ.get('ARGO_SERVER', 'http://localhost:2746')
global_config.token = os.environ.get('ARGO_TOKEN', '')
global_config.verify_ssl = False # Set to True in production
def my_task_func(name: str):
print(f"Hello, {name} from Hera!")
with Workflow(generate_name="my-first-hera-workflow-", entrypoint="my-entrypoint") as w:
my_task = Task(
name="my-entrypoint",
inputs=[Parameter(name="message", default="World")],
func=my_task_func,
arguments=["{{inputs.parameters.message}}"]
)
w.submit()