Run Workflows triggered by a python script locally

Hello community,

I ran into the need of running a KNIME workflow in the background triggered by a python script in my machine.

I found old posts from 2020 about using knimepy but I don’t know if the new version of KNIME will support this approach or whether it is compatible with simple python scripts running locally.

I know the KNIME server could be a solution, but it sounds overkilling to me given that I just want to have it locally in my mac to avoid having to open the KNIME analytics platform to push the button of run workflow.

Any help will be appreciated.

Regards,

AG.

I think this should still work. Maybe you can give it a try. There are also examples how to run knime workflows from Jupyter notebooks.

1 Like

Thanks @mlauber71 but it did not manage to see the how your workflow can solve my problem.

I am running a python script from Outside KNIME. Running this python script should trigger a KNIME workflow, which results in generation of a CSV file in my computer. Then I use the results of this file to continue working outside of KNIME.

At the moment I have crafted the following python script that I am running from VS code:


 import knime

knime.executable_path = "/Applications/KNIME 5.3.0.app/Contents/MacOS/knime"
workflow_path = "/Volumes/.../BAG system"

with knime.Workflow(workflow_path) as wf:
    wf.execute()
    output_table = wf.data_table_outputs[0]  # Retrieve first output table
    print(output_table)

But nothing happens.

If I use subprocess:

import subprocess

knime_executable = "/Applications/KNIME 5.3.0.app/Contents/MacOS/knime"
workflow_path = "/Volumes/KNIME Worflows in use/knime-fundamentals/Obsidian applications/RAG system"

subprocess.run([
    knime_executable,
    "-nosplash",
    "-application", "org.knime.product.KNIME_BATCH_APPLICATION",
    "-workflowDir=" + workflow_path,
    "-reset"
])

I get a long error from KNIME about java.

Do you know what I am doing wrong?

btw I am using a M1 mac.

Thanks,

AG.