Importing Data from Python Scripts

You can import data directly from a Python script, either by entering the script directly in the task, or by referencing an external script file.

This type of operation may be useful if you want to apply an external script to data before using it in a Rulex workflow, in order to perform a specific operation that requires a low-level programming language, such as deciphering badly formatted text files.

Prerequisites

  • a Rulex process has been created

  • Python 3 software has been installed where Rulex is running.

  • IPython3 has been installed on the machine where Rulex is running (via pip install ipython)

Additional tabs

The following additional tabs are provided:


Procedure

  1. Drag and drop the Python Import Bridge task onto the stage.

  2. Double click the Python Import Bridge task.

  3. Configure the script options as described in the table below.

  4. Save and compute the task.

Python options

Name

PO

Description

General options

Get Python script from file

scriptfromfile

Select this option to import the Python script directly from a file, and not by manually entering the Python code below.

Select Python script

filename

Click here and browse to the external file, which contains the Python script you want to apply.

This option will be enabled only if you have selected the Get Python script from file option.

Store output in

outref

Select the type of table that will be populated by the dictionary selected as output in the Python script.

Possible options are:

  • Dataset (i.e. the main data table)

  • Clusters

  • Advanced association structure (association rules, bundle hypotheses or replacement rules table).

Name of the output data frame in Python script

routputname

Enter the name you want to use in the Python script to reference the data Rulex will receive from Python. This data will populate the table according to the option selected in Store output in

Select file to store Python console output

debugfilename

Browse to the text file where the Python script console output will be saved after execution of the Python Bridge task.

Python Code

rcode

Enter the Python script code you want to execute.

This text box is enabled only if you have not selected the Get Python script from file option.

Connection options

Select path to Python command

rcommand

Browse to the location of the IPython interpreter command, which can be found in the Python installation folder. If you have administrator rights on the machine, it will be sufficient to enter ipython3.exe

If the path is not correctly specified, the Python Bridge task will not work correctly and a warning message will be displayed.

The Python task cannot compute if another process is pending. You can monitor this on Windows via the Task Manager (Processes).

Python host

rhostname

Enter the address of the host where Python is installed. If Rulex is running on the same desktop where it is installed you can enter localhost.

Python port

rport

Specify the port used for data transfer between Rulex and Python (i.e. input table transfer from Rulex to Python, output dictionary transfer from Python to Rulex).

System firewall exception

Make sure you define an exception in the system firewall on this port, allowing the data exchange between the two applications. Otherwise, the task will not be executed and a warning message will be displayed signaling a communication problem between Rulex and Python.

Python port for signals

rportaux

Specify the port used for signal transfer between Rulex and Python (i.e. progress bar updates).

System firewall exception

Make sure you define an exception in the system firewall on this port, allowing the data exchange between the two applications. Otherwise, the task will not be executed and a warning message will be displayed signaling a communication problem between Rulex and Python.

setprogress command

The setprogress command, which updates a progress bar, increasing it by a corresponding progress percentage, can be set via the Python code text box, or via a referenced external script.

For instance, if the current progress value is 10 and a setprogress(10) command is executed, the progress bar is increased by (100-10)*10% = 9%, that is to 19%.

If Python libraries are referenced in the script (through the “library” Python instruction), you should install them previously, in their native Python environment, instead of inserting the install.packages instruction directly in the Python Code window. However, the install.packages command can be run from Rulex only if Rulex itself is executed with administrative privileges: otherwise, a warning concerning this issue will be raised and the execution will not terminate.