Python Script (legacy)

Allows executing a Python script in a local Python environment. The environment has to be configured under File → Preferences → KNIME → Python or via flow variable, as described in the KNIME Python Integration Installation Guide .
This node supports Python 2 and 3. It also allows to import Jupyter notebooks as Python modules via the knime_jupyter module that is available in the node's Python workspace.
Multiple input and output ports of various types can dynamically be added to the node and used in the script. See section Ports below for a description of all available inputs and outputs, and how they can be addressed in the Python script.

Options

Script

Editor
The script in the editor panel in the center will later be executed to generate this node's outputs. Execute script executes the full script while Execute selected lines executes only the currently selected part of the script.
The editor optionally provides autocompletion (CTRL + Space) if the Python module jedi is installed in the Python environment used by the node.
Note that when in the editor, only a limited number of input rows is made available to the script for interactivity reasons. This can be configured via the Row limit (dialog) option (see below).
Flow variables
The pane on the left side of the editor panel lists the available flow variables. A double click on a flow variable inserts the corresponding identifier at the current cursor position in the editor panel.
Workspace
The pane on the right side of the editor panel is the workspace and lists the currently defined identifiers in the running Python instance. Reset workspace will remove the output of all past script executions.
Console
The console under the editor panel displays the standard output and standard error of the running Python instance as well as other information.
Row limit (dialog)
Limits how many rows of input data are loaded into the dialog. This is useful to maintain the interactivity of script executions in the dialog when there are lots of input data. Changing this value only takes effect after resetting the node's workspace or closing and reopening the dialog.
When actually executing the node, all of the input data will be considered regardless of this option, of course.
Missing values (Integer, Long)
By default, Number (Integer) and Number (Long) columns containing missing values are converted into double in Python because double is the only numeric type that has a built-in representation for missing values (NaN). Converting longs to doubles, however, introduces imprecision. The conversion may be avoided by replacing missing values with so-called sentinel values.
To convert missing values into sentinel values before script execution, check the first option. To convert sentinel values back into missing values after script execution, check the second option.
Three different types of sentinel values are available: MIN_VAL (the smallest possible value for the column's data type), MAX_VAL (the largest possible value for the column's data type), or a custom integer value to be entered into the text field. The chosen sentinel values will be available in the node's workspace as INT_SENTINEL and LONG_SENTINEL, respectively.
Rows per chunk
Large tables are broken into chunks when they are transferred between Python and Java. This option controls how many rows are included in each chunk. The default value is intended for tables containing few columns having numeric types. If larger data types like images or text are transferred, a single chunk may exceed the maximum allowed buffer size. In this case lowering the value of this parameter helps getting reasonably sized chunks.

Executable Selection

Use Python version
Allows to choose the Python version used to execute the node.
Conda environment propagation
Allows to choose whether to obtain the Python executable corresponding to the Python version selected above from the KNIME Preferences or from flow variable.
  • Use KNIME preferences: Use the Python executable configured under File → Preferences → KNIME → Python to execute the node.
  • Use Conda flow variable: Use the Conda environment propagated by the selected Conda flow variable to execute the node. The Python version of the environment must match the version selected above.

Templates

Create from editor...
Clicking on this button creates a new template based on the script in the editor panel of the script tab.
Note: User defined templates can be found in the folder: knime-workspace/.metadata/knime/sourcecode-templates/python-script-dynamic-ports.
Remove selected
Clicking on this button removes the selected template.
Note: Templates provided by plugins cannot be removed.
Apply selected
Replaces the script in the editor panel of the script tab with the selected template.

Flow Variables

pythonVersionOption
Controls the Use Python version option above. The variable accepts either python2 or python3 as value.
python2Command
Controls which Python 2 environment is employed by this node if it is configured to use Python 2. This allows using an environment that is different from the one that is configured in the KNIME Preferences. The flow variable accepts the path to a Python start script, executable, or Conda environment as described in the KNIME Python Integration Installation Guide .
python3Command
Controls which Python 3 environment is employed by this node if it is configured to use Python 3. This allows using an environment that is different from the one that is configured in the KNIME Preferences. The flow variable accepts the path to a Python start script, executable, or Conda environment as described in the KNIME Python Integration Installation Guide .
sentinelOption
Controls the type of sentinel value. The flow variable accepts MIN_VALUE, MAX_VALUE, or CUSTOM as value. Setting this variable to CUSTOM makes the node respect the custom integer value either set in the dialog or via the sentinelValue flow variable.

Input Ports

Icon
No description for this port available.
Icon
An input object. Input objects are automatically unpickled and made available to the Python script as variables whose names follow the scheme: input_object_<index>. For example, variable input_object_1 refers to the object at the first inbound Pickled object port.
Icon
An input table. In the Python script, input tables are available as variables of type pandas.DataFrame. The names of the variables follow the scheme: input_table_<index>. For example, variable input_table_1 refers to the table at the first inbound Table port.

Output Ports

Icon
No description for this port available.
Icon
An output table. The corresponding variable must be defined in the Python script. It must be of type pandas.DataFrame and its name must follow the scheme: output_table_<index>. For example, in order to populate the first outbound Table port, variable output_table_1 must be defined as described.
Icon
An output image. The corresponding variable must be defined in the Python script. It must be either a string describing an SVG image or a byte array encoding a PNG image. Its name must follow the scheme: output_image_<index>. For example, in order to populate the first outbound Image port, variable output_image_1 must be defined as described.
Icon
An output object.The corresponding variable must be defined in the Python script. It can be of any type that can be pickled. Its name must follow the scheme: output_object_<index>. For example, in order to populate the first outbound Pickled object port, variable output_object_1 must be defined as described.

Popular Predecessors

Views

Standard output
The text sent by Python to its standard output during the execution of this node.
Error output
The text sent by Python to its error output during the execution of this node.

Workflows

Links

Developers

You want to see the source code for this node? Click the following button and we’ll use our super-powers to find it for you.