The knode Command

The knode command manages KNIME nodes implemented as Cactvs scripts.

knode addparam

knode addparam khandle dialogtype name ?attribute value?..
knode addparam khandle dialogtype name attributedict
k.addparam(dialog,name,?attributedict?)
k.addparam(dialog,name,attribute=value,...)

Add a user-configurable parameter to the node definition. The first argument after the handle is the type of interface widget which should be used on the KNIME node configuration panel. It can be one of:

The next argument is the name of the parameter. It is used to retrieve the parameter value or other attributes via the knode param command. It must be unique within a node. The maximum number of parameters for a node is 128. After configuration, querying the value attribute of a parameter by means of knode param returns the default value. Node that you cannot explicitly configure the value attribute.

The rest of the arguments are processed after the two mandatory initial arguments have been parsed. The additional attributes which can be set for a parameter depend on its data type and dialog widget class. These are all recognized attributes:

The command returns the current number of parameters on the node.

knode addport

knode addport khandle direction ?name? ?attribute value?...
knode addport khandle direction name attributedict
k.addport(direction,?name?,?attributedict?)

Add a port to the node definition. The first argument is either input or output and defines the port direction. The second argument it the port name. If the name is omitted, a name following the schema input0...n or output0..n is automatically generated. Without additional attributes, the port class is datatable. The maximum number of ports for a node is 16.

Additional attributes may me specified as attribute/value pairs or as a dictionary. The following attributes are recognized:

knode bglisten

knode bglisten ?port?...
Knode.Bglisten(?port?,...)

Add one or more background RPC communication listener threads. If no port is specified, a lister on the standard port is configured. It can be examined and set via control variable ::cactvs(knimenode_default_port) , its default is 16570.

An interpreter with an active background listener can receive and process RPC commands, for example from a KNIME workbench.

It is currently not possible to process Python node scripts in background threads due to Python multi-threading limitations.

The command has no return value.

knode bgunlisten

knode bgunlisten ?port?...
Knode.Bgunlisten(?port?,...)

Cancel listener threads active on specific ports. If no port is specified the standard port is assumed. The standard port can be examined and set via control variable ::cactvs(knimenode_default_port) , its default is 16570.

Trying to cancel non-existing listener threads is silently ignored. If a thread is currently processing a RPC request, the cancellation happens after the current request has been served.

It is currently not possible to process Python node scripts in background threads due to Python multi-threading limitations.

The command has no return value.

knode clearparameters

knode clearparameters khandle
k.clearparameters()

Delete all currently defined parameters from the node.

The command can be shorted to knode clearparams .

The return value is the original node handle or reference.

knode clearports

knode clearports khandle
k.clearports()

Delete all currently defined ports from the node.

The return value is the original node handle or reference.

knode compile

knode compile khandle ?jarfile?
k.compile(?jarfile=?)

Compile the node definition into a KNIME workspace node. The result is a JAR file which can be copied into the drop-in directory of a local KNIME installation. By default, the name of the JAR file is constructed from the vendor domain, node name (or explicit Java class name, if set) and version, but it is also possible to request a custom JAR file name. A typical auto-generated JAR file name looks like com.xemistry.ExcelSaver_1.1.jar. After a KNIME program restart, the new node automatically shows up in the node browser.

The JAR file contains RPC interface code for communication with a node execution server, a normal-looking KNIME workspace node with ports, a configuration panel automatically assembled from the defined configuration parameters , auto-generated node documentation, node browser location and icon data, and the node definition code. When a node in a KNIME workspace connects to a node server, the node definition is transmitted and the node instantiated on the server. This node is then executed in the configuration and execution phases in response to normal KNIME workflow actions. Parameter configuration information is extracted from the configuration panel and sent in the configuration phase, together with column definition information of data cell ports. Port contents are either sent before execution, or, in streaming mode, parallel to execution. Likewise, result data from the node server is sent back either when the node execution has finished, or streamed in parallel to its execution.

Within the scripted node environment, data table port data appear as toolkit tables, graph port data as port objects, and image data as byte blob.

KNIME can be finicky about Java compiler versions. It may be necessary to configure the javac attribute so that the right compiler release is picked up.

knode configure

knode configure khandle ?paramname paramvalue?...
knode configure khandle paramdict
k.configure(?paramname,paramvalue?,...)
k.configure(paramdict)

Invoke the configuration script of the node, optionally with a custom set of configuration options. The value attribute of the named parameters are persistently changed to the new values, if this is allowable with respect to parameter type, minimum/maximum values, etc. If the setting of a parameter fails, an error is reported.

This command is typically used during node development, without a KNIME workspace connection. If a node is connected to a KNIME workspace, its configuration procedure is automatically invoked at the proper times.

Note that this command does not set input port data, which is at least partially defined when connected to a KNIME workspace via the output ports of connected nodes. During debugging outside of KNIME , suitable input port data for processing must be provided by script commands which either set the data explicitly, (see knode port command) or by setting input port filenames. In the latter case, their content is automatically loaded and transfered to the input ports before the configuration code is run.

If the configuration succeeds, the node is ready for execution by knode exec in debug mode.

The return value of the command is a list of the table handles or references, network handles or references and image bytes on the input ports in port index order.

knode config is a command alias.

knode create

knode create ?attribute value?...
knode create ?attributedict?
Knode(?attribute,value?,...)
Knode(attributedict)
Knode.Create(?attribute,value?,...)
Knode.Create(attributedict)

Create a new KNIME node object. Without any arguments an unconfigured default object is created. Additional arguments can be used to set attributes. The recognized attributes are the same as for the knode set command.

The return value is the handle or reference of the new KNIME node object.

knode delete

knode delete ?khandle?...
knode delete all
k.delete()
Knode.Delete(?khandle/kref?,...)
Knode.Delete(“all”)

Delete specific or all KNIME node objects from the toolkit interpreter instance. The return value is the number of successfully deleted KNIME node objects.

In case the node is actively connected with a KNIME workspace, the connection is cut and a network error is reported in the workspace. Generally, nodes actively connected to a workspace should only be deleted from there, which is performed by RPC communication from the workspace to the toolkit interpreter. This command is still useful for example in node development and compilation environments.

knode execute

knode execute khandle
k.execute()

Execute a KNIME node by invoking its execution procedure. It is assumed that the node has been successfully configured (see knode configure command).

This command is typically used during node development, without a KNIME workspace connection. If a node is connected to a KNIME workspace, its execution procedure is automatically invoked at the proper times.

If the execution succeeds, output port result data may be accessed by knode port commands.

The return value of the command is a list of the table handles, network handles and image bytes on all the output ports in port index order.

The command may be abbreviate to knode exec .

knode exists

knode exists khandle
k.exists()
Knode.Exists(handle/ref)

Check whether a node handle is valid.

knode get

knode get khandle attribute
k.get(attribute)
k.attribute
k[attribute]

Retrieve the current value of a node object attribute. All attributes which can be set can also be read (see knode set command). In addition, there are a couple of read-only attributes:

knode list

knode list ?pattern?
Knode.List(?pattern=?)

Return a list of all currently existing KNIME object handles. If a filter pattern is specified, only handles matching it are listed. The pattern syntax is the same as in the standard Tcl command string match .

knode listen

knode listen ?port?
Knode.Listen(?port=?)

Start a foreground RPC listener. If no port is specified, the standard port is assumed. It can be examined and set via control variable ::cactvs(knimenode_default_port) , the default is 16570.

This command does not return except on error or the listener loop has been canceled by outside actions.

knode log

knode log khandle ?level? message
k.log(?level=?,?message=?)
k.log(message)

Add a log message to the node state. The level may be one of debug, info, warning, error or fatal. The default level is info. The message text is a free-form string. If the message is empty, no actual log entry is written.

Log messages are transmitted to a connected KNIME workspace and show up in the console window.

The command returns the original node handle or reference.

knode parameter

knode parameter khandle parametername ?attribute?
k.parameter(name=,?attribute=?)

Retrieve an attribute or the current value of a node configuration parameter. Within the context of a live KNIME workbench connection, these are automatically extracted from the configuration panel settings and available both in the configuration and execution procedures.

The current parameter values (but not other attributes) can also be accessed from within a node configuration or execution script as global array variable : :params .

If no attribute is specified, the parameter value is retrieved.

Parameters may be accessed via the parameter name or the 0-based parameter index.

knode getparam , knode getparameter and knode param are command aliases.

The following attributes are recognized:

knode port

knode port khandle portname attribute
knode port khandle portname table ?tablehandle|#new? ?isowner?
knode port khandle portname imageblob ?imagebytes?
knode port khandle portname imagefile ?filename?
knode port khandle portname network ?networkhandle|#new? ?isowner?
knode port khandle portname expectedrows ?count?
k.port(name=,attribute=,?value=?,?isowner=?)

Retrieve information about a a specific port, or set it. Ports can be identified by their name, or by their 0-based port index. Some port attributes can be modified. In this case, one or two additional parameters for the new attribute value follow the attribute name argument.

The following attributes are recognized:

knode read

knode read filename
Knode.Read(filename)

Create a node by reading an XML -based node definition file. The default node file suffix is .knd ( KNIME node definition), but this is not enforced.

The return value is the handle or reference of the new node.

knode readblob

knode readblob blobdata
Knode.Readblob(blobdata)

Create a new by reading an XML -based node definition file directly from string data.

The return value is the handle or reference of the new node.

knode reset

knode reset khandle
k.reset()

Reset the node so that its state is the same as after a knode create command. All result data, port and parameter definitions as well as accumulated log messages are deleted and the basic node attributes are reset to default values.

The command returns the original node handle or reference.

knode resetlog

knode resetlog khandle
k.resetlog()

Reset the accumulated log information of the node. When connected to a KNIME workspace, log messages which have been transferred to the workspace are automatically deleted. Also, any new call to the node configuration or execution functions resets the log.

The command returns the original node handle or reference.

knode set

knode set khandle ?attribute value?...
knode set khandle dict
k.set(?attribute,value?,...)
k.set(dict)
k.attribute = value
k[attribute] = value

Set zero or more node object attributes. The recognized attributes are:

Modes inportrows[0-2] , inporteods[0-2], outportrows[0-2] and outporteods[0-2] follow the same schema.

knode subcommands

knode subcommands
dir(Knode)

List all subcommands of the knode command.

knode write

knode write khandle ?filename?
k.write(?filename=?)

Write the node definition to an XML -based file which is suitable for reading with the knode read command.

If no filename is specified, its name is derived from the node name with a .knd ( KNIME node definition) suffix. If an explicit empty filename is specified (including None for Python ), an in-memory string blob is produced, without writing to a file.

The definition file only saves the node definition with all attributes, ports and parameters, but no execution state or execution result information.

The return value is the file name, or, in case of blob output, the definition file contents.

knode writeconfig

knode writeconfig ?filename?
Knode.Writeconfig(?filename=?)

Write the current system configuration regarding the KNIME node subsystem to a file. If no file name is given, the default configuration filename csconfig.xml in the current directory is used.

Files of that name are automatically read on start-up if they are in the current working directory, or in a standard location such as the home directory or the Cactvs installation directory, or passed as a program option when the interpreter is started. This makes it easy to maintain a custom node execution environment without explicitly setting many custom configuration variables.

The return value is the file name.

knode writedoc

knode writedoc khandle ?filename?
k.writedoc(?filename=?)

Write a HTML file for a node which looks very much like the contents of the node description panel in the KNIME workbench. The original documentation compiled into the node JAR files is XML -coded, so this is not exactly the same data. The constant contents of the RPC and Source tabs are omitted.

If no node name is specified, a name is automatically constructed from the node name and a .html suffix. If an explicit empty filename is specified (including None for Python ), the output is an in-memory string blob, not a file

The return value is the file name, except in case of blob output, when it is the HTML file contents.

knode writescript

knode writescript khandle ?filename?
k.writescript(?filename=?)

Write a Tcl or Python script which, when run, faithfully recreates the node definition and writes out a new XML node definition file and a new KNIME JAR file. Editing these scripts in the context of custom node development is much more convenient than manipulating the content of the native XML -based node definition file. For simple node source code distribution, the XML format is more suitable.

If the file name has a . tcl suffix, the output is a Tcl script. The script language is automatically switched to Python if the file name has a . py suffix. If none of these suffixes is used, the script language configured via the defaultlanguage node attribute is used. If that is also unset, Tcl is the default. If no file name argument is used, the file name is constructed from the node name and the appropriate language suffix. If an explicit empty filename is specified (including None for Python ), the output is an in-memory string blob, not a file.

The return value is the file name, except in case of blob output, when it is the script file contents.

knode writetest

knode writetest khandle ?filename?
k.writetest(?filename=?)

Automatically generate a Tcl or Python test script for a node. The command line arguments for the script are port data file names for all non-optional input ports, optionally file names to store the output of ports, and a parameter dictionary. The script contains readable comments to self-document its use.

If the file name has a . tcl suffix, the output is a Tcl script. The script language is automatically switched to Python if the file name has a . py suffix. If none of these suffixes is used, the script language configured via the defaultlanguage node attribute is used. If that is also unset, Tcl is the default. If no file name argument is used, the file name is constructed from the node name with a _test name modification and the appropriate language suffix. If an explicit empty filename is specified (including None for Python ), the output is an in-memory string blob, not a file.

The return value is the file name, except in case of blob output, when it is the script file contents.