Configuration¶
A node receives its settings through two channels: a static string map that comes from the schema file, and a typed map that the graph editor builds from what your node describes in on_get_configuration(). After this page you can describe settings with typed entries (text, toggle, slider, dropdown), read them back in on_configure() with one helper call, keep static defaults that always parse, and test both channels without a running platform.
Two channels, one hook¶
Static config |
Typed dynamic_config |
|
|---|---|---|
Python type in on_configure |
ScalarMap[str, str] |
MessageMap[str, NodeConfigEntry] or None |
| Where the values come from | The configuration block of your <module>_schema.json, handed to every node created from that schema |
What the editor collected in the fields your on_get_configuration() described |
| Value type | Always strings | One typed branch per entry (string, toggle, range, single select, multi select) |
| Declared in the schema file | Yes | No. The typed map only exists at run time |
| When you first see it | On the first configure | On the first configure after the user has edited the node |
Both maps arrive together. The SDK always calls on_configure(config, dynamic_config) with two positional arguments, and passes None for the typed map when the graph carries no typed values yet. A one-parameter override of on_configure therefore fails with a TypeError.
sequenceDiagram
participant Editor
participant SDK
participant Node as Your node
Editor->>SDK: InitializeNode
SDK->>Node: on_get_configuration()
Node-->>Editor: typed entries (defaults, labels, widgets)
Editor->>SDK: ConfigureNode (graph with configuration + dynamicConfiguration)
SDK->>Node: on_configure(config, dynamic_config)
Describe the settings: on_get_configuration()¶
on_get_configuration() returns a dict[str, NodeConfigEntry]. Each entry carries the default value, the widget the editor should render, and display metadata. Plain strings are not accepted: every value is wrapped in a NodeConfigValue.
def on_get_configuration(self) -> dict[str, NodeConfigEntry]:
"""Typed defaults the editor renders as a text field and a toggle."""
return {
"light_ip": NodeConfigEntry(
configValue=NodeConfigValue(stringValue=DEFAULT_LIGHT_IP),
displayLabel="Light IP address",
description="Address of the light this node controls.",
required=True,
),
"simulate": NodeConfigEntry(
configValue=NodeConfigValue(toggleValue=ToggleValue(enabled=False)),
displayLabel="Simulate",
description="Log commands instead of sending them to the device.",
),
}
The SDK calls this hook right after the node object is initialized, before the first configure, and again whenever the editor asks for the current configuration. Two rules follow from that:
- Defaults must not depend on anything set up in
on_configure(). Use module constants or attributes assigned in__init__. - The hook may be called on a node that is already configured. Returning the current values (as the cloud tutorial does with its endpoint) is fine; returning secrets is not. Mask them.
If the hook raises, the SDK wraps the exception in a NodeConfigurationError and the initialize call fails.
Entry fields and value branches¶
NodeConfigEntry fields:
| Field | Type | # |
|---|---|---|
configValue |
NodeConfigValue |
1 |
displayLabel |
string |
2 |
description |
string |
3 |
unit |
string |
4 |
readOnly |
bool |
5 |
required |
bool |
6 |
isOverridable |
bool |
7 |
NodeConfigValue.value branches (exactly one is set):
| Branch | Type | Renders in the UI as |
|---|---|---|
stringValue |
string |
free-text field |
toggleValue |
ToggleValue |
on/off toggle |
rangeValue |
RangeValue |
slider (min / max / step) with unit |
singleSelectListValue |
SingleSelectListValue |
dropdown |
multiSelectListValue |
MultiSelectListValue |
multi-select list |
displayLabel, description, unit, readOnly, required and isOverridable are passed through to the editor unchanged. The SDK itself never reads them, so they cannot enforce anything inside your node: validate required values yourself in on_configure().
Widgets beyond text and toggle¶
A slider is a RangeValue with min, max, value and step (all floats). The image tutorial uses one for its scale setting:
def on_get_configuration(self) -> dict[str, NodeConfigEntry]:
"""Describe the settings the UI shows for this node (typed entries)."""
return {
"scale": NodeConfigEntry(
configValue=NodeConfigValue(
rangeValue=RangeValue(
min=self.MIN_SCALE,
max=self.MAX_SCALE,
value=self.DEFAULT_SCALE,
step=0.1,
)
),
displayLabel="Scale",
description="Resize factor applied to the grayscale image (1.0 keeps the size)",
required=True,
)
}
Lists take their options from allowedItems and their current choice from selectedItem (single) or selectedItems (multi):
from neuraverse.models.v1.gen.business.node_graph_pb2 import (
MultiSelectListValue,
NodeConfigEntry,
NodeConfigValue,
SingleSelectListValue,
)
mode = NodeConfigEntry(
configValue=NodeConfigValue(
singleSelectListValue=SingleSelectListValue(
allowedItems=["fast", "accurate"], selectedItem="fast"
)
),
displayLabel="Mode",
)
channels = NodeConfigEntry(
configValue=NodeConfigValue(
multiSelectListValue=MultiSelectListValue(
allowedItems=["rgb", "depth", "ir"], selectedItems=["rgb"]
)
),
displayLabel="Channels",
)
Read the values: on_configure()¶
Declare both parameters and read each key once, preferring the typed value and falling back to the static string:
def on_configure(
self,
config: ScalarMap[str, str],
dynamic_config: Optional[MessageMap[str, NodeConfigEntry]] = None,
) -> None:
# Typed values from the editor win; the schema's static string map is the fallback.
self._light_ip = get_config_value("light_ip", config, dynamic_config) or DEFAULT_LIGHT_IP
# get_config_value renders a toggle as the string "true" / "false".
self._simulate = get_config_value("simulate", config, dynamic_config) == "true"
self._paused_flag = False
# on_configure runs again on every re-configure: release the old handle first.
self._release_device()
self._device = FakeLightDevice(self._light_ip)
self.log_info(f"Connected to light at {self._light_ip} (simulate={self._simulate})")
get_config_value(key, config, dynamic_config) from neuraverse_sdk.utils.config does the lookup for you. It looks in dynamic_config first, converts the typed branch to a string, and falls back to config.get(key). It returns None when neither map has the key.
| Typed branch | What get_config_value returns |
|---|---|
stringValue |
The string as is |
toggleValue |
"true" or "false" |
rangeValue |
str(rangeValue.value), for example "0.5" |
singleSelectListValue |
selectedItem, or the static fallback when nothing is selected |
multiSelectListValue |
The first entry of selectedItems only, or the static fallback when the list is empty |
Because everything comes back as a string, you convert it yourself: float(...), int(...), == "true". When you need the full list of a multi-select, or the slider bounds, read the proto directly:
entry = dynamic_config["channels"] if dynamic_config and "channels" in dynamic_config else None
if entry is not None and entry.configValue.WhichOneof("value") == "multiSelectListValue":
channels = list(entry.configValue.multiSelectListValue.selectedItems)
Validate what you read and raise on bad input: NodeDataError.missing() when a required key is absent, NodeDataError.invalid() when its value is unusable (see Errors). The SDK logs the error, moves the node to the error state and reports the failed configure to the caller, which is what you want for a wrong IP address or an out-of-range value. On an SDK older than 2.42.0, raise NodeConfigurationError from neuraverse_sdk.utils.exceptions instead.
Keys must match
Use the same key in the schema's configuration block, in on_get_configuration() and in your get_config_value calls. The smart home test asserts exactly this: the set of static keys equals the set of typed keys.
Static defaults must parse¶
The static configuration block in the schema file holds strings only. The editor seeds every new node with them, so whatever on_configure() does to a value must succeed on the default: float("0-100") crashes a freshly dropped node before the user has typed anything. Keep the defaults minimal and valid, and keep the typed defaults in on_get_configuration() in sync with them. The block itself is described in Schema file.
Keys the platform adds for you¶
The SDK registers three static entries alongside your node. They describe where the node runs and are managed by the platform, not by you.
| Key | Branch | Meaning |
|---|---|---|
node_external_target |
stringValue |
Host and port under which the node is reachable from outside the cluster |
is_remote |
toggleValue |
Whether the node is reachable from outside the cluster |
node_deployment_host |
stringValue |
Host and port of the registry the node registered with |
Do not declare these keys (or node_namespace, which the engine adds when it lists the palette) in your schema or in on_get_configuration(). You may read them from config if your node needs to know where it runs, but never write them.
Re-configure semantics¶
on_configure() is not a one-time constructor. The SDK runs it on every configure request for the same node object: the first time a graph is configured, after a stop and re-configure, and when the user edits a setting and re-applies the graph. Write it so that it can run repeatedly:
- Keep parsed values on
self, never in module globals. - Release the resource opened by the previous configure before opening the new one. The smart home node calls its
_release_device()helper first for exactly this reason, and its test checks that the old handle is closed. - Put the final release in
on_cleanup(), the final step of the hard stop. See the smart home node'scleanupsection in Smart home tutorial.
The config and dynamic_config maps are the only inputs you should rely on at configure time. Do not read data ports or publish from on_configure(); the dataflow is wired but the graph has not started.
Testing both channels¶
Both maps are plain protobuf containers, so a unit test can call the hook directly with dictionaries:
from neuraverse.models.v1.gen.business.node_graph_pb2 import (
NodeConfigEntry,
NodeConfigValue,
ToggleValue,
)
node = SmartLightNode()
node.data_flow = FakeDataFlow()
static = {"light_ip": "10.0.0.9", "simulate": "true"}
node.on_configure(static, None) # static channel only, strings as in the schema file
assert node._simulate is True
typed = {"simulate": NodeConfigEntry(configValue=NodeConfigValue(toggleValue=ToggleValue(enabled=False)))}
node.on_configure(static, typed) # the typed channel wins over the static fallback
assert node._simulate is False
See Testing for the test helpers used above.
Mock Runner differences
The Mock Runner never fills the static map: config is always empty, so every default has to come from on_get_configuration(). Its UI renders stringValue, toggleValue, rangeValue and singleSelectListValue entries, but when you press Configure it sends the values back as a toggle for booleans and as a stringValue for everything else. A slider therefore arrives as stringValue("0.5"), not as a rangeValue. Code that goes through get_config_value does not notice the difference; code that reads configValue.rangeValue.value directly returns 0.0 in the mock. A multiSelectListValue entry has no widget of its own there and falls through to a plain text field.
Configured types for external data input¶
Typed JSON input uses the ROS type resolved during configuration. Generic inputs must have a concrete type before a value can be injected.
No new node configuration key is required. Declare the input as usual and install its message package in the node image. Reconfiguration clears prior input values; injected values do not change the schema or resolved type. See typed JSON input.