Only supported for KNIME versions <=4.3, no more changes will be made to this repo as of Nov 2023.
Abstract Python wrapper KNIME node and helpers. Used for development of KNIME nodes calling Python scripts.
The nodes in Scripting>Python folder of the node repository (nodes part of the KNIME Python integration
plugin) the end-user needs to paste Python code in a text area in the node dialog.
Nodes derived from this repo will have a Python script included in their jar file and the dialog of the node will contain no source code text area.
The included Python script is not editable by the end-user, but can read options from dialog like the input column name.
Instructions for KNIME node developers that want to call a Python script. Several steps must be performed:
The releases of this repository are available in the https://3d-e-chem.github.io/updates
update site.
Configure target platform by adding the https://3d-e-chem.github.io/updates
update site with Abstract Python wrapper KNIME node and helpers
software.
To make use of it in a Tycho based project, add to targetplatform/KNIME-AP-4.0.target
file the following:
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="nl.esciencecenter.e3dchem.python.plugin" version="0.0.0"/>
<repository location="https://3d-e-chem.github.io/updates"/>
</location>
To implement the node a dependency is needed for the plugin add tests.
To do this add nl.esciencecenter.e3dchem.knime.python
as a required plugin to the plugin/META-INF/MANIFEST.MF
and tests/META-INF/MANIFEST.MF
file.
Create your node config class extended from the nl.esciencecenter.e3dchem.python.PythonWrapperNodeConfig
class.
Overwrite the constructor to add required Python modules with the addRequiredModule("<module name>")
method.
PythonWrapperNodeConfig class are configured for a single input table called input_table
and a single output table called output_table
.
To change the the number and names of input and/or output tables, override the constructor.
In your nodes dialog the Python options panel should be added by adding the following to the dialog constructor
pythonOptions = new PythonOptionsPanel<PredictMetabolitesConfig>();
addTab("Python options", pythonOptions);
To save the Python options to disk you must call the pythonOptions.saveSettingsTo(config)
followed by config.saveToInDialog(settings)
in the save*To()
method of the dialog.
To load the Python options from disk you must call the config.loadFromInDialog(settings)
followed by pythonOptions.loadSettingsFrom(config)
in the load*From()
methods of the dialog.
Inside Python script the following variables are special:
options
, dictionary filled from Java with PythonWrapperNodeConfig.getOptionsValues() method, to read frominput_table
, Pandas Dataframe with input data table, to read fromoutput_table
, Pandas Dataframe with output data table, to assign with valueflow_variables
, dictionary of flow variables, to get or put key/value pairs
flow_variables['warning_message']
, if key exists then value will be set as warning message of nodeThe Python script should be located in same directory as the model.
Create your node model class extended from the nl.esciencecenter.e3dchem.python.PythonWrapperNodeModel
class.
Overwrite the python_code_filename
fields in the constructor, this is the name of the Python script.
To run tests which execute the node a call to PythonWrapperTestUtils.init()
is required
this will add the KNIME-Python utility scripts to the Python path and configure it to use the python3
executable in current PATH.
To build the plugin and run the tests run the following command:
mvn verify
An Eclipse update site will be made in p2/target/repository
repository.
The update site can be used to perform a local installation.
Steps to get development environment setup based on https://github.com/knime/knime-sdk-setup#sdk-setup:
KNIME Analytics Platform (4.0) - nl.esciencecenter.e3dchem.python.targetplatform/KNIME-AP-4.0.target
target definition.targetplatform/KNIME\ Analytics\ Platform.launch
file and selecting Run As → KNIME Analytics Platform
. The KNIME instance will contain the target platform together with all extensions defined in the workspace.During import the Tycho Eclipse providers must be installed.
mvn org.eclipse.tycho:tycho-versions-plugin:set-version -DnewVersion=<version>-SNAPSHOT
command.mvn package
, will create update site in p2/target/repository
mvn install -Dtarget.update.site=<path to update site>