Use Jupyter notebooks
Existing Jupyter notebooks (.ipynb files) can be accessed within Python Scripting nodes using the knime.scripting.jupyter (knupyter) module.
Import notebooks
To treat a notebook as a standard Python module, use the load_notebook function.
python
import knime.scripting.jupyter as knupyter
# Define the folder path and notebook filename
notebook_directory = "knime://knime.workflow/data/"
notebook_name = "analysis_logic.ipynb"
# Load the notebook as a module
my_notebook = knupyter.load_notebook(notebook_directory, notebook_name)
# Call functions defined in the notebook code cells
# output_table = my_notebook.calculate_results(knio.input_tables[0])View notebook content
To inspect the contents of a notebook without importing it as a module, use knupyter.print_notebook(path, filename). This outputs the textual content of every cell to the node console.
Configuration options
Both the load_notebook and print_notebook functions support the following optional parameters:
notebook_version: An integer representing the major version of the Jupyter format. Use this if the version cannot be detected automatically from the file metadata.only_include_tag: A string representing a custom cell tag. When specified, only cells annotated with this tag are loaded. Use this to exclude cells containing demo code, visualizations, or documentation that are not required for the Python module.
INFO
Jupyter notebook support requires the IPython, nbformat, and scipy packages. These are included in the default bundled environment. See Bundled Packages for the full package list.
Example workflow
For a complete example of how to use Jupyter notebooks in KNIME, see the Python Scripting with Jupyter notebooks example workflow on the KNIME Hub.