Port Scripts from Legacy Python Nodes
Before KNIME Analytics Platform v4.7, Python scripting used the KNIME Python Integration (legacy) with different node names, a different API, and a 1-based port numbering convention. This page explains how to migrate those scripts to the current Python Script and Python View nodes.
INFO
The current Python Script node was introduced as Python Script (Labs) in v4.5 and promoted to stable in v4.7. The main improvements are:
- Significantly faster data transfer via Apache Arrow
- A bundled Python environment — no setup needed to start
- A unified API through the
knime.scripting.iomodule - Support for both Pandas DataFrames and PyArrow Tables
- Batch processing for datasets larger than RAM
Quick adapter
Add the following three lines to the top and bottom of your legacy script to make it work in the current Python Script node:
python
import knime.scripting.io as knio
# Add at the top — replaces `input_table_1`
input_table_1 = knio.input_tables[0].to_pandas()
# ... your original legacy script goes here unchanged ...
# Add at the bottom — replaces `output_table_1`
knio.output_tables[0] = knio.Table.from_pandas(output_table_1)Port numbering change
0-based vs. 1-based port indexing
The legacy nodes used 1-based port numbering (e.g. input_table_1, input_table_2), while the current nodes use 0-based indexing (e.g. knio.input_tables[0], knio.input_tables[1]). Update all your port references when migrating.
| Legacy | Current |
|---|---|
input_table_1 | knio.input_tables[0].to_pandas() |
input_table_2 | knio.input_tables[1].to_pandas() |
output_table_1 | knio.output_tables[0] = knio.Table.from_pandas(df) |
flow_variables['x'] | knio.flow_variables['x'] (unchanged) |
knime package name clash
If the package knime is installed via pip in your environment, importing knime.scripting.io will fail with:
No module named 'knime.scripting'; 'knime' is not a packageRun pip uninstall knime to remove the conflicting package. The knime.scripting.io module is provided automatically by KNIME via the PYTHONPATH — it does not need to be installed.