0 ×

Python Script

KNIME Python nodes version 4.3.2.v202103021016 by KNIME AG, Zurich, Switzerland

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.
Use Python version
Allows to choose the Python version that is used to execute the node. The available environments of the different versions can be checked and configured under File → Preferences → KNIME → Python. They can also be set via flow variable (see section Flow Variables below).
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.

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 Preferences. The flow variable accepts the path to a Python start script or executable 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 Preferences. The flow variable accepts the path to a Python start script or executable 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.

Output Ports

Icon
No description for this port available.

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

Installation

To use this node in KNIME, install KNIME Python Integration from the following update site:

KNIME 4.3

A zipped version of the software site can be downloaded here.

You don't know what to do with this link? Read our NodePit Product and Node Installation Guide that explains you in detail how to install nodes to your KNIME Analytics Platform.

Wait a sec! You want to explore and install nodes even faster? We highly recommend our NodePit for KNIME extension for your KNIME Analytics Platform. Browse NodePit from within KNIME, install nodes with just one click and share your workflows with NodePit Space.

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.