Problem to launch a workflow from a Python script

@giuseppeR just to wrap this up. You could run a KNIME workflow from Python. The software would have to be installed on the machine (obviously) and it would run in the background

# https://pypi.org/project/knime/
# pip install knime

import knime
import pandas as pd

# Change the executable_path to point at a particular KNIME install.
# May alternatively be set via OS Environment Variable, 'KNIME_EXEC'.
knime.executable_path = r"/Applications/KNIME 4.6.0.app/Contents/MacOS/knime"

# Use a with-statement to set the inputs, execute, and get the results.
# https://hub.knime.com/-/spaces/-/latest/~bWh_i0_N_OyhEJf9/
# you might have to adapt the workflow path
with knime.Workflow(r"00_Random_Forest_knimepy") as wf:
    wf.execute()
    output_table = wf.data_table_outputs[0]  # output_table will be a pd.DataFrame

output_table.head()

I am not sure about the knio packages in later KNIME versions I can not find these functions. But this would work. You might have to figure out how to address more than one table output. There are also examples how to use input files (GitHub - knime/knimepy).

4 Likes