MCPcopy Create free account
hub / github.com/ScrapeGraphAI/Scrapegraph-ai / BaseNode

Class BaseNode

scrapegraphai/nodes/base_node.py:12–235  ·  view source on GitHub ↗

An abstract base class for nodes in a graph-based workflow, designed to perform specific actions when executed. Attributes: node_name (str): The unique identifier name for the node. input (str): Boolean expression defining the input keys needed from the state. o

Source from the content-addressed store, hash-verified

10
11
12class BaseNode(ABC):
13 """
14 An abstract base class for nodes in a graph-based workflow,
15 designed to perform specific actions when executed.
16
17 Attributes:
18 node_name (str): The unique identifier name for the node.
19 input (str): Boolean expression defining the input keys needed from the state.
20 output (List[str]): List of
21 min_input_len (int): Minimum required number of input keys.
22 node_config (Optional[dict]): Additional configuration for the node.
23 logger (logging.Logger): The centralized root logger
24
25 Args:
26 node_name (str): Name for identifying the node.
27 node_type (str): Type of the node; must be 'node' or 'conditional_node'.
28 input (str): Expression defining the input keys needed from the state.
29 output (List[str]): List of output keys to be updated in the state.
30 min_input_len (int, optional): Minimum required number of input keys; defaults to 1.
31 node_config (Optional[dict], optional): Additional configuration
32 for the node; defaults to None.
33
34 Raises:
35 ValueError: If `node_type` is not one of the allowed types.
36
37 Example:
38 >>> class MyNode(BaseNode):
39 ... def execute(self, state):
40 ... # Implementation of node logic here
41 ... return state
42 ...
43 >>> my_node = MyNode("ExampleNode", "node", "input_spec", ["output_spec"])
44 >>> updated_state = my_node.execute({'key': 'value'})
45 {'key': 'value'}
46 """
47
48 def __init__(
49 self,
50 node_name: str,
51 node_type: str,
52 input: str,
53 output: List[str],
54 min_input_len: int = 1,
55 node_config: Optional[dict] = None,
56 ):
57 self.node_name = node_name
58 self.input = input
59 self.output = output
60 self.min_input_len = min_input_len
61 self.node_config = node_config
62 self.logger = get_logger()
63
64 if node_type not in ["node", "conditional_node"]:
65 raise ValueError(
66 f"node_type must be 'node' or 'conditional_node', got '{node_type}'"
67 )
68 self.node_type = node_type
69

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected