Skip to content

Inputs and outputs

These properties retrieve data from or pass data back to KNIME Analytics Platform. The length of the input and output lists depends on the number of input and output ports of the node.

Example: If you have a Python Script node with two input tables and one input object, access them via knime.scripting.io.input_tables[0], knime.scripting.io.input_tables[1], and knime.scripting.io.input_objects[0].

attribute knime.scripting.io.flow_variables : Dict[str, Any]

A dictionary of flow variables provided by the KNIME workflow. New flow variables can be added to the output of the node by adding them to the dictionary. Supported flow variable types are numbers, strings, booleans and lists thereof.

attribute knime.scripting.io.input_objects : List

A list of input objects of this script node using zero-based indices. This list has a fixed size, which is determined by the number of input object ports configured for this node. Input objects are Python objects that are passed in from another Python script node'soutput_object port. This can, for instance, be used to pass trained models between Python nodes. If no input is given, the list exists but is empty.

attribute knime.scripting.io.input_tables : List[Table]

The input tables of this script node. This list has a fixed size, which is determined by the number of input table ports configured for this node. Tables are available in the same order as the port connectors are displayed alongside the node (from top to bottom), using zero-based indexing. If no input is given, the list exists but is empty.

attribute knime.scripting.io.output_images : List

The output images of this script node. This list has a fixed size, which is determined by the number of output images configured for this node. The value passed to the output port should be a bytes-like object encoding an SVG or PNG image.

Examples
python
>>> import knime.scripting.io as knio
...
... data = knio.input_tables[0].to_pandas()
... buffer = io.BytesIO()
...
... pyplot.figure()
... pyplot.plot('x', 'y', data=data)
... pyplot.savefig(buffer, format='svg')
...
... knio.output_images[0] = buffer.getvalue()

attribute knime.scripting.io.output_objects : List

The output objects of this script node. This list has a fixed size, which is determined by the number of output object ports configured for this node. Each output object can be an arbitrary Python object as long as it can be pickled. Use this to, for example, pass a trained model to another Python script node.

Examples
python
>>> model = torchvision.models.resnet18()
... ...
... # train/finetune model
... ...
... knime.scripting.io.output_objects[0] = model

attribute knime.scripting.io.output_tables : List[Union[Table, BatchOutputTable]]

The output tables of this script node. This list has a fixed size, which is determined by the number of output table ports configured for this node. You should assign a Table or BatchOutputTable to each output port of this node.

Examples
python
>>> import knime.scripting.io as knio
... knio.output_tables[0] = knio.Table.from_pandas(my_pandas_df)

attribute knime.scripting.io.output_view : Optional[NodeView]

The output view of the script node. This variable must be populated with a NodeView when using the Python View node. Views can be created by calling the view(obj) method with a viewable object. See the documentation of view(obj) to understand how views are created from different kinds of objects.

Examples
python
>>> import knime.scripting.io as knio
... import plotly.express as px
...
... fig = px.scatter(x=data_x, y=data_y)
... knio.output_view = knio.view(fig)