Hera

6.0.0 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart demonstrates how to define a DAG (Directed Acyclic Graph) workflow using Hera, where tasks 'B' and 'C' run in parallel after 'A' completes, and 'D' runs after both 'B' and 'C' are finished. The `echo` function is converted into an Argo script template using the `@script` decorator. The workflow is then submitted to an Argo Workflows server configured via environment variables or a default local endpoint.

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.")

view raw JSON →