Script

Run Python over up to eight numeric inputs and return up to four numeric outputs.

What it does

Runs a small Python function directly in the graph. The code defines an execute(inputs, cx) function that reads named values like in_0 from inputs and returns a dictionary of named outputs like out_0. Input Count and Output Count add or remove numbered ports, up to eight inputs and four outputs.

A new node carries a one-in, one-out passthrough. Shell access for running subprocess commands is off by default and must be switched on deliberately.

When to use it

ParameterTypeDefault
codeString"def execute(inputs, cx): ..."
input_countNumber1
output_countNumber1
allow_shellBooleanfalse
in_0Number
in_1Number
in_2Number
in_3Number
in_4Number
in_5Number
in_6Number
in_7Number

Gotchas

An unused input port is not read, and any output key the function does not return falls back to zero. There is no need to fill every port every time.

Shell access is off by default. Switch on Allow Shell only where the script needs to run external commands. Left off, the node executes nothing outside its own Python code.

Raising Input Count or Output Count adds numbered ports (in_0, in_1, …, out_0, out_1, …), but the execute function still has to read and return those exact keys. Adding a port does not wire it into the code.

Worked example

  1. Add a Script node. Leave Input Count and Output Count at 1 to start.

  2. Open the code field and edit the execute function, for example multiplying in_0 by two and returning it as out_0.

  3. Wire a Number node into in_0 and watch out_0 update.

  4. For more values in or out, raise Input Count or Output Count and reference the new in_N / out_N keys in the code.

  5. Only if the script needs to shell out to another program, switch on Allow Shell.

See also

Attribute Wrangle · Lua · p5.js · Numbers, signals & audio