Python Source (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.

Options

Script

Editor
The script in the editor panel in the center will be executed to generate this node's output. "Execute script" will execute the full script while "Execute selected lines" will only execute the currently selected part of the script.
The editor optionally provides autocompletion (CTRL + Space) if the Python module jedi is installed.
Flow variables
The pane on the left side of the editor panel lists the available flow variables. A double click on a flow variable will insert 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 standard output, standard error, or 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.
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 value will be available as INT_SENTINEL and LONG_SENTINEL respectively, in the node's workspace.
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-source.
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

This node has no input ports

Output Ports

Icon
The output table contained in the variable output_table which needs to be defined by the user script and has to be of type pandas.DataFrame.

Views

Standard output
The text sent by Python to the standard output during the execution of this node.
Error output
The text sent by Python to the 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.