Python-Defined Workflows
Graphbook allows you to define your workflows in Python. This is more suited for advanced users who want to have more control over their workflows. When using a Python-defined workflow, users cannot make structural changes to the graph in the UI. However, they can still view the graph, adjust parameters, run the workflow, and monitor the results. Dragging nodes or making any parameters changes will not modify the underlying Python code.
Create a Graph
To define a workflow in Python, create a Python file (e.g., my_workflow.py
), and define your workflow in a decorated function belonging to the graphbook.Graph
class.
For example:
Create Nodes
To create a step, use the graphbook.Graph.step()
method.
To create a resource, use the graphbook.Graph.resource()
method.
Set Parameters
To set parameters, use the graphbook.GraphNodeWrapper.param()
method.
All nodes, steps and resources, can accept parameters.
@g()
def _():
# ...
step_0.param("param_0", 42)
resource_0.param("param_1", "hello")
step_0.param("param_1", my_resource) # Also accepts previously defined resources
Order of Configuration
One of the greatest things about Graphbook is the ease of forwarding your function and class parameters to the UI. Thus, it is important to mention how parameter values are overwritten. The order of configuration is as follows:
Default values defined within the class or function such as the ones used with
graphbook.param()
.Values defined in the Python-defined workflow file will overwrite the default values.
Values defined in the UI will overwrite the workflow file ones.
Bind Steps
To bind steps to other steps, use the graphbook.GraphStepWrapper.bind()
method.
With this method, you can forward an output of one step to the input of another step.