Hera
Hera is a Python library that enables orchestration of Python code on Argo Workflows. It allows users to construct and submit Argo Workflows entirely in Python, simplifying interaction with the underlying Argo API. Currently at version 6.0.0, Hera maintains an active release cadence with frequent updates.
Warnings
- breaking The experimental decorator feature for `DAG`, `Steps`, `Container`, and `script` (introduced in v5.16) has been removed in v6.0.0. This means users should revert to the context manager pattern or the standard `@script()` decorator if they were using the `Workflow.dag()` or `Workflow.steps()` decorators.
- breaking Hera v6.0.0 migrates core Hera classes to Python dataclasses and uses Pydantic v2 API models internally where Pydantic is still needed, removing support for Pydantic v1. If your custom script functions relied on Hera's internal Pydantic v1 models or if your project mixes Hera with Pydantic v1 models, you must upgrade your Pydantic dependency to v2 and address any compatibility issues.
- breaking Hera v5.27.0 dropped support for Python 3.9. Users on Python 3.9 will need to upgrade their Python environment to 3.10 or newer to use Hera versions 5.27.0 and later.
- gotcha Hera requires an active Argo Workflows server in a Kubernetes cluster for workflow submission. It does not run workflows locally or manage Argo deployments. Proper authentication (e.g., Bearer token) and server accessibility (e.g., port-forwarding) must be configured.
- gotcha The Python package name for Hera changed from `hera-workflows` to `hera` for versions 5.0.0 and above. Attempting to install `hera-workflows` for newer Hera versions will result in an outdated installation.
- gotcha Functions decorated with `@script()` are executed as containerized templates on Argo. This means the Docker image specified in the decorator (or default global image) must contain the Python environment and all dependencies required by the decorated function. Local imports and non-standard libraries need to be bundled into the image.
Install
-
pip install hera -
pip install hera[yaml]
Imports
- Workflow
from hera.workflows import Workflow
- script
from hera.workflows import script
- DAG
from hera.workflows import DAG
- Steps
from hera.workflows import Steps
- global_config
from hera.shared import global_config
Quickstart
import os
from hera.workflows import DAG, Workflow, script
from hera.shared import global_config
# Configure Hera to connect to your Argo Workflows server
# Set ARGO_SERVER_HOST and ARGO_SERVER_TOKEN environment variables
# For local testing, ensure Argo Server is port-forwarded (e.g., kubectl -n argo port-forward service/argo-server 2746:2746)
global_config.host = os.environ.get("ARGO_SERVER_HOST", "http://localhost:2746")
global_config.token = os.environ.get("ARGO_SERVER_TOKEN", "") # Use actual token if required
@script(image="python:3.11")
def echo(message: str):
"""A simple Python function to echo a message."""
print(message)
with Workflow(
generate_name="hera-dag-diamond-",
entrypoint="diamond",
namespace="argo", # Ensure this matches your Argo Workflows namespace
labels={
"example": "true",
"sdk": "hera",
}
) as w:
with DAG(name="diamond"):
A = echo(name="A", arguments={"message": "Task A"})
B = echo(name="B", arguments={"message": "Task B"})
C = echo(name="C", arguments={"message": "Task C"})
D = echo(name="D", arguments={"message": "Task D"})
A >> [B, C] >> D
# Submit the workflow
try:
submitted_workflow = w.create()
print(f"Workflow '{submitted_workflow.metadata.name}' submitted successfully.")
print(f"Access UI at {global_config.host}/workflows/{submitted_workflow.metadata.namespace}/{submitted_workflow.metadata.name}")
except Exception as e:
print(f"Error submitting workflow: {e}")
print("Please ensure your Argo Workflows server is running and accessible, and ARGO_SERVER_HOST/TOKEN are configured correctly.")