Execute Workflow with Python - Inspect Output

I am interested in executing a workflow via python, as I am exploring if I could use this path to “autograde” assignments that students would submit.

The post below was helpful:
https://forum.knime.com/t/problem-to-launch-a-workflow-from-a-python-script/60885/15

My issue: My python script runs without error, but seemingly it doesnn’t return any data.

wf = knime.Workflow("/Users/path/knime-workspace/brock_test3")
wf.execute()
wf.data_table_outputs

Where brock_test3 is the folder created after creating the flow in Knime. Here is the painfully simple flow that summarizes a publicly accessible csv.

image

I expected the output of the sorter node to made available as a data table after my code snippet ran.

I suspect that I am overlooking something obvious. Any help would be greatly appreciated.

@Brock_Tibert welcome to the KNIME forum. In think you will have to save the data from inside knime. If you want to continue within Python you could export as parquet file or into a SQLite database.

1 Like

@mlauber71 Thanks for the prompt reply!

My use-case is that I want students to complete assignments with Knime, submit their file(s), at which point I would be able to use python to programmatically inspect their work and output by executing their workflow. For example, do they get the output I am expecting? Does their workflow have errors?

Above is an example of a simple task; read data from the web and summarize a column of data. I was hoping/expecting to see the output I am showing in the screenshot as a pandas data frame, which the library suggests is possible. In my case, I was getting empty output (zero-length lists).

It’s entirely possible I am not properly thinking about how to use knimepy correctly. That said, it’s intriguing that I might be able to programmatically inspect workflows for the reason I mentioned above.

@Brock_Tibert you would need a Container Output (Table) – KNIME Community Hub in the knime workflow to use the syntax

output_table = wf.data_table_outputs[0] # output_table will be a pd.DataFrame

Otherwise the python module would not know what data to use.

Another approach could be to try and call the workflow from another one and apply the input and output port and then see if everything would work.

So you might have to tell your students to use these container outputs.

Workflows can also be stored and being re-used like in this AutoML example. You will have to toy around how to use the input saved with the original workflow. If you want to re-use it with other data you will have to configure it:

2 Likes

Thank you for the detailed response. I still have a lot to learn, but I will review the resources you linked above during winter break. I know it’s ambitious to think I can pull off “autograding” but it’s worth a shot!

2 Likes