Skip to content

Scripting API Reference (knime.scripting.io)

The knime.scripting.io module is the primary API for interacting with KNIME data inside Python Script and Python View nodes. It is automatically available on the PYTHONPATH — you do not need to install it.

For the full API reference, see Python Scripting API.

Import

python
import knime.scripting.io as knio

Tables

SymbolDescription
knio.input_tables[i]Read-only input table at port index i (0-based).
knio.output_tables[i]Assign a knio.Table or knio.BatchOutputTable to write output.
knio.Table.from_pandas(df)Create a KNIME table from a Pandas DataFrame.
knio.Table.from_pyarrow(table)Create a KNIME table from a PyArrow Table.
table.to_pandas()Convert to Pandas DataFrame.
table.to_pyarrow()Convert to PyArrow Table.

Batches

SymbolDescription
knio.BatchOutputTable.create()Create an empty batch output table.
input_table.batches()Returns an iterable of batches. Each batch supports .to_pandas() / .to_pyarrow().
batch_output.append(data)Append a Pandas DataFrame or PyArrow Table as a batch.

Objects and images

SymbolDescription
knio.input_objects[i]Pickled input object at port index i.
knio.output_objects[i]Assign a picklable object to write output.
knio.output_images[i]Assign an SVG string or PNG bytes to write an image.

Flow variables

SymbolDescription
knio.flow_variables['name']Read or write flow variables as a dictionary.

Views (Python View node only)

SymbolDescription
knio.output_viewAssign the return value of a knio.view_* function.
knio.view(obj)Auto-detect format and create a view.
knio.view_html(html)View from an HTML string.
knio.view_svg(svg)View from an SVG string.
knio.view_png(data)View from PNG bytes.
knio.view_jpeg(data)View from JPEG bytes.
knio.view_matplotlib(fig?)View from an active or given matplotlib figure.
knio.view_seaborn(fig?)View from an active or given seaborn figure.
knio.view_plotly(fig)View from a Plotly figure. Set custom_data to Row ID for selection sync.
knio.view_ipy_repr(obj)View from an object with an IPython _repr*_ function.

Example: matplotlib

python
import knime.scripting.io as knio
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])

knio.output_view = knio.view_matplotlib(fig)

Example: Plotly with selection sync

To synchronize row selection between a Plotly chart and other KNIME views, set custom_data to the row index:

python
import knime.scripting.io as knio
import plotly.express as px

df = knio.input_tables[0].to_pandas()

fig = px.scatter(
    df,
    x="my_x_col",
    y="my_y_col",
    color="my_label_col",
    custom_data=[df.index],
)

knio.output_view = knio.view_plotly(fig)

Output images from views

The optional image output port is populated automatically when the view is SVG, PNG, or JPEG, or can be converted to one:

  • matplotlib / seaborn: PNG or SVG depending on the format argument.
  • Plotly: requires the kaleido package.
  • IPython objects: uses repr_svg, repr_png, or repr_jpeg (first available).
  • HTML: set an image representation manually via the view_html call.

You can also populate knio.output_images[0] directly:

python
import knime.scripting.io as knio
import matplotlib.pyplot as plt
import io

fig, ax = plt.subplots()
ax.bar(["A", "B"], [3, 5])

buf = io.BytesIO()
fig.savefig(buf, format="png")
knio.output_images[0] = buf.getvalue()

Jupyter notebook support

SymbolDescription
knime.scripting.jupyter.load_notebook(dir, name)Load a notebook as a Python module.
knime.scripting.jupyter.print_notebook(dir, name)Print cell contents to console.

Next steps