Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 42 Current »


Applies a Python script to the current data node. The script takes as input the result table of the current data node and, if specified, the result tables of other data nodes in the same project, and manipulates the current result table.

Python scripts can be stored on the server's file system

The operator interprets Python code using different Python versions depending on the TIS release used:

TIS releasePython version used
up to 6.1Python 3.6
from 6.2Python 3.7
from 6.3Python 3.8
from 6.6Python 3.9

Modules from the Python Standard Library can be imported. Other modules can be imported if they have been included in the current deployment.

As a convention, 4-space indentation should be used instead of tabs, see PEP Style Guide(warning) When pasting python scripts into the operator's editor, tab indentations are converted to 4-space indentations.

The operator looks for the functions simple_main and main to start execution. The simple_main function loads the whole result table into memory and the main function uses an Event loop to provide only the parts of the result tables necessary for the current computation. Further, simple_main can only access the result table of the current data node and no other data nodes. 

The environment variable LANGUAGE (os.environ['LANGUAGE']) is set to the user's language. The project's language is ignored.

Helper functions


get_or_add_column(name, type, columns, types)


set_value(columns, types, row, name, type, value)




Simple main with datalists (example adds two columns)

Note: columns and types are updated! Therefore the are send back to the sender via the reference of the call.
If you want to make column and types new, then use e.g. columns.clear and the update mechanism.
Never assign a new object to columns,types by =    as this would be destructive.
import datetime

def simple_main(params, mylist, types, columns):

	out_list = []
	input_cols = len(columns)

	columns.update({'DATE0':input_cols, 'TIME0':input_cols+1})
	types.update({, input_cols+1:datetime.time})

	for row in mylist:

	return out_list

Main using generators
def main(params,inputs,outputs):

	columns = {}
	types = {}

	async def getcolfilter():
		nonlocal columns

		v = None
		while 1:
			v = yield v

	i0 = inputs[0]
	o0 = outputs[0]
	return [ (i0, getcolfilter(), o0) ], {i0: (lambda: (types, columns))}

Project File


Filename Python Script


opt.Path to TIS File containing the Python script-
Evaluation Timeout (msec)System.Int

Maximum execution time. If exceeded, the operation terminates with an error.

This value must be set between 1.000ms and 2.147.483.647ms.

Input Datanode 1System.Objectopt.An additional input data node
Input Datanode 2System.Objectopt.An additional input data node
Input Datanode 3System.Objectopt.An additional input data node
Input Datanode 4System.Objectopt.An additional input data node
Input Datanode 5System.Objectopt.An additional input data node
Input Datanode 6System.Objectopt.An additional input data node


See also Useful sample Python Scripts

Consume multiple input tables

First 2 input tables are consumed by the sponge function into a list of lists mylists. 



In the flush method the output is generated. If the value of column A is found in the second table, the row is duplicated and the value is set in the third column. 

# aggregates complete input into a list
# flushes list to output
def main(params, inputs, outputs):
    async def sponge(i0,i1):
        mylists = [[],[]]
        async for v in i0:
        async for v in i1:
        yield mylists
    async def flush(o):
        mylists = yield
        await o.asend(None) # prime o
        for v in mylists[0]:
            await o.asend(v)
            for v2 in mylists[1]:
                if v2[0] == v[0]:
                    v[2] = v2[1]
                    await o.asend(v)

    o0 = outputs[0]
    return [ (sponge(inputs[0],inputs[1]), flush(o0)) ]

Related topics

  • No labels