# Python API

# Run Flow Using runflow

Assume you have a Runflow spec file examples/hello.hcl.

# File: hello.hcl

# Define a flow naming as "hello".
# There can only be only one flow declaration per flow file.
flow "hello" {

  # The task defines what should be done.
  # In this example, we run a bash command `echo`.
  task "bash_run" "echo" {
    command = "echo 'hello world'"
  }

}

Run this flow:

>>> from runflow import runflow
>>> runflow(path='examples/hello.hcl', vars={})
hello world

Another option is through import string:

>>> runflow(module='examples.hello:flow', vars={})
hello world

You can also provide it with the source of flow spec:

>>> source = """
... flow "hello_world" {
...   task "bash_run" "echo" {
...     command = "echo 'hello world'"
...   }
... }
... """
>>> runflow(source=source, vars={})
hello world

Added in v0.5.0.

# Run Flow Using Autoloader

Assume you have a Runflow spec file mypackage/hello.hcl.

# File: hello.hcl

# Define a flow naming as "hello".
# There can only be only one flow declaration per flow file.
flow "hello" {

  # The task defines what should be done.
  # In this example, we run a bash command `echo`.
  task "bash_run" "echo" {
    command = "echo 'hello world'"
  }

}

Import "runflow.autoloader" and you can import this flow in Python code.

>>> import runflow.autoloader
>>> from mypackage.hello import flow
>>> flow
<runflow.core.Flow object at 0x10ca67f10>

Run it by runflow function:

>>> runflow(flow=flow, vars={})

If you prefer the low-level API, try this:

>>> import asyncio
>>> asyncio.run(flow.run(vars={}))
hello world

Added in v0.5.0.