LooT Manuals
Deutsch

Scripts

Write your own computations in Python or TypeScript, version them, try them out and run them as a component – in an isolated environment.

Overview#

A script is a component you write yourself in Python or TypeScript. It belongs to your tenant, has immutable versions and appears in the library under the classification "Script". A script runs like any other component: you set it up, bind its ports to nodes and start or stop it.

Scripts are stateless: whatever a run needs to know comes in through inputs, and results leave through outputs. The state of a run (for example the window of a moving average) lives only as long as the run.

You open scripts from the Components view (group Library, scripts first) or from the Workflows view (section Scripts).

Creating a script#

  1. In the Components view, open the ⋮ menu and choose New …. (In a workflow, New … is in the toolbar.)
  2. Choose the Write a script tile. You need the "Create scripts" permission on the tenant.
  3. Enter the name and choose the language (default: Python).
  4. Confirm. The script is created from a template as version 1.0.0 and its tab opens pinned.

Name and language cannot be changed later. The name is unique within the tenant, ignoring case, and consists of letters, digits, _ and -.

If created from a workflow, New … also creates a component and a box on the canvas; in the Components view only the script is created.

The script tab#

The tab has these sections:

SectionContent
OverviewDescription, ports and the versions.
SourceThe editor with highlighting for the language, completion and help.
PortsTable of inputs and outputs as read from the header line, with the change against the last version and the reasons.
VersionsList of all versions, the source of a version and a line-by-line comparison with the current one.
Try outTest run of the latest saved version, see below.
In operationComponents of your tenant that use this script.
PermissionsPermissions on the script.

The header shows the name, the classification "Script" with the language, Set up … (turns the script into a component) and Delete script. The footer shows the saved state of the latest version and the buttons Try out and Save as new version.

A dot on the tab marks unsaved changes. When you close the tab, the workbench asks whether to save as a new version, discard or cancel.

Help in the editor#

The editor knows the language: it highlights keywords and header lines, completes ctx accesses and the port names from the header line, and offers snippets that you insert with Tab. The Help button in the editor footer or F1 shows a help panel beside the editor. It follows the cursor and shows the matching statement, ports or ctx members for the current line.

Structure of a script#

The description is a comment at the start of the source, the header line. LooT reads it without running the script. The comment character is # in Python and // in TypeScript.

LineMeaning
loot:mode job or loot:mode reactiveRequired, exactly once: the mode of the script
loot:description textDescription (once)
loot:input name type [required] [nullable] [default=value] [-- description]An input; type float, integer, bool, string or dynamic
loot:output name type [nullable] [-- description]An output
loot:max-duration secondsDeadline per run

required and default exclude each other; nullable allows gaps (null). The header ends with the first line of code (in TypeScript, before the first import).

The code defines the function run(ctx). The ctx object is the same in both languages, in the spelling of the language (Python snake_case, TypeScript camelCase):

PurposePythonTypeScript
Entry pointdef run(ctx):export function run(ctx) or export async function run(ctx)
Latest valuectx.inputs.get(name)ctx.inputs.get(name)
Value presentctx.inputs.has(name)ctx.inputs.has(name)
Values in orderfor item in ctx.inputs.follow(name)for await (const item of ctx.inputs.follow(name))
Snapshotctx.inputs.sequence(name)ctx.inputs.sequence(name)
Write an outputctx.outputs.write(port, value, time)ctx.outputs.write(port, value, time)
Logctx.log.info(text)ctx.log.info(text)
Error and abortctx.error(text)ctx.error(text)
Check for stopctx.stop_requested, ctx.sleep(s)ctx.stopRequested, await ctx.sleep(s)

Example: a reactive script that raises an alarm as soon as the measured value reaches the threshold. Gaps in the input stay gaps in the output.

python
# loot:mode reactive
# loot:input value float required nullable -- measured value
# loot:input threshold float default=10
# loot:output alarm bool nullable

def run(ctx):
    for item in ctx.inputs.follow("value"):
        if item.value is None:
            ctx.outputs.write("alarm", None, item.timestamp)
        else:
            ctx.outputs.write("alarm", item.value >= ctx.inputs.get("threshold"), item.timestamp)

The same in TypeScript:

typescript
// loot:mode reactive
// loot:input value float required nullable -- measured value
// loot:input threshold float default=10
// loot:output alarm bool nullable
import type { Context } from "loot";

export async function run(ctx: Context): Promise<void> {
    for await (const item of ctx.inputs.follow("value")) {
        ctx.outputs.write("alarm", item.value === null ? null : item.value >= ctx.inputs.get("threshold"), item.timestamp);
    }
}

If you bind value in the component to a node such as Brewery/Plant.Line1.Temperature and alarm to a bool node, the script writes the alarm there continuously.

The languages in detail#

  • Python (version 3.13) ships with numpy, scipy and pandas; import loot is not needed. Every import costs start-up time in every run (numpy about half a second, scipy.signal several seconds); in frequently running job scripts, import only what you need.
  • TypeScript (Node 24) only strips the types; it does not check them. enum, namespace with content and parameter properties do not work. Import types from loot only with import type. Available packages are arquero, simple-statistics, d3-array, ml-matrix, fft.js and date-fns. A long, purely synchronous computation does not see the stop; wait with await ctx.sleep(…).

Versions#

Every save with changed source creates a new, immutable version; the first is 1.0.0. Saving without a change creates none. The server assigns the version number according to the changes to the ports:

ChangeNew version
Ports unchanged (only code, description or deadline)Patch (1.0.0 → 1.0.1)
New optional input, new output, different default value, relaxed inputMinor (1.0.1 → 1.1.0)
Mode changed, port removed, type changed, stricter input, new required input without default valueMajor (1.1.0 → 2.0.0)

While you type, the tab shows which version saving would assign; the Ports section names the reasons. Components stay on their version until you switch them (see Components). A script box in a workflow shows "x.y.z available" when a newer version exists.

Trying out#

The Try out section starts a test run of the latest saved version; you cannot test an intermediate draft this way. With Save and test you first save as a new version and then start. A test run writes nothing into nodes.

  • For job scripts, enter the inputs.
  • For reactive scripts, also give an input sequence (one value per line, at most 1000) and a deadline in seconds (default 10, at most 120). After the last value, at the latest after the deadline, the test run stops by itself.

The result shows the state, outputs, error and log. Errors in the script appear with the line ("Line 7: …"); Go to line jumps there in the editor. A test run needs the Write permission on the script.

Limits and sandbox#

Every run starts in its own isolated environment (sandbox): without network, with a read-only file system, without credentials and with limited CPU, memory, number of processes and files. The script sees only its input values; LooT data and tokens never reach it. The server writes the outputs with the permissions of the person who created the binding.

LimitValue
Size of the sourceat most 256 KiB
Portsat most 64 per side (inputs/outputs)
Deadline per runmax-duration (1 second to 30 days), at most the operator's upper limit: by default 60 s for jobs and 24 h for reactive runs; longer values are cut
Memory per run128 MiB by default (operators can change it)
Input queue1000 values

If a run exceeds the deadline or the limits, it ends with an error message. A script that cannot run because no runner is registered for its language or the sandbox does not start reports this as a run error; contact your operator in that case.

Permissions#

PermissionGranted onAllows
Create scriptsthe tenantcreating scripts
Readthe scriptseeing source, versions and ports
Writethe scriptchanging the source (new version), test runs
Managethe scriptgranting permissions, deleting the script

Whoever creates a script has all permissions on it; so do tenant admins and system admins. Running belongs to the component: someone who may only start a component using the script does not see the source. Name, ports and version of the script are visible to all members of the tenant in the library.

Delete script (Manage permission) removes the script with all versions and its test runs. While a component uses it or a run is active, the server rejects the deletion and names the number.

You can also manage scripts from the command line.

Typical traps#

A product of Rheinwert Datentechnik · rheinwert.deVersion: LooT 0.9.10