Skip to main content

Build Your Own Nodes

Overview

Each node in BoCoFlow represents a specific operation or function. It is straightforward to create your own nodes based on your own Python code.

Node Wrapper

tip

You can always use the nodes in the pdbmdauto-flow project as examples to create your own nodes.

1. Build a start node

note

Start Node: Such a node will not have any input ports. The code will not examine the input data from the previous node.

This is a simple template node that will ask a user to provide a name as input and will passing a hello world 'name' message to the next node.

copy and paste the following code into a new file named hello_world_node.py

# Import dependencies for the node
from bocoflow_core.node import Node
from bocoflow_core.parameters import StringParameter
import json

class HelloWorldNode(Node):
"""
A simple hello world node that takes a name as input and outputs a greeting.
"""
# Basic node properties
name = "Hello World"
num_in = 0 # input port number
num_out = 1 # output port number

# Parameters shown in the GUI
OPTIONS = {
'user_name': StringParameter(
label="Your Name",
default="BoCoFlow",
docstring="Name of the person to greet"
),
}

def execute(self, predecessor_data, flow_vars):
"""
Process the input data and produce output.

Args:
predecessor_data: Data from previous nodes (empty for this start node)
flow_vars: Parameters set through the GUI

Returns:
A greeting message
"""
# Get the name from parameters
name = flow_vars["user_name"].get_value()

# Create greeting message
greeting = f"Hello, {name}!"

# Return the result
return json.dumps({"greeting": greeting})

I am demonstrating how to use such a start node in BoCoFlow in the following video: