Use Python in retool loops

I have two Python functions, and each function needs to iterate through every row of the table. Additionally, I need to conditionally decide which function to run for each row.

Hello @Rashmika_Lakshan!

Unfortunately python is not supported for the 'loop' block component, but you can grab table.data and pass it into a 'python block' where you can loop over the data.

You can then chose how to handle the conditional logic, either nest in inside the python block or pass the data from the loop to a branch block.

1 Like

Hi @Jack_T ,

Thank you for the clarification! I appreciate your guidance on handling conditional logic with the 'python block'.

Are there any plans to support Python directly for the 'loop' block component in the future? It would be a helpful feature for many use cases.

Thanks again for your assistance!

@Rashmika_Lakshan of course no problem!

That is a great question, I am not sure if that is on the roadmap but I can check.

The current 'loop block' component, is under the hood a JS code block that runs a for loop with the logic of writing out he code abstracted away with the GUI.

Which I found out while learning about the difference between the loop block and a JS block that runs a loop inside it's code on execution.

So in many ways a python block would be the exact same thing as a python block with a loop inside the code, just without the GUI on top. If there are any major features missing or specific use cases that would make sense to add let me know!

For python the use of libraries makes it easier for the code executor to run line by line to import in the needed libraries for execution which might be tricky to do with a loop block :thinking: