How can I call a query from the query library from Python block in Workflow?
There is no direct way to call a query from the query library from a Python block in Retool Workflow. However, there are a few workarounds that you can use:
1. Use the Resource Query block
You can create a Resource Query block and select the query from the query library in the Query field. Then, you can use the Output of the Resource Query block as the input for your Python block.
2. Use a SQL client
You can use a SQL client library, such as psycopg2, to connect to the Retool database and execute the query from the query library. Then, you can use the results of the query as the input for your Python block.
3. Use a Retool API
You can use the Retool API to create a new query or execute an existing query. Then, you can use the results of the query as the input for your Python block.
Here is an example of how to call a query from the query library from a Python block in Retool Workflow using the Resource Query block:
import json # Get the output of the Resource Query block query_output = workflow.get_block_output("resource_query") # Parse the JSON output data = json.loads(query_output) # Do something with the data for row in data: print(row)
Currently, Retool does not support user-imported Python libraries in Python blocks. This means that you cannot use any third-party Python libraries in your Python blocks. However, Retool does preinstall a number of popular Python libraries, such as numpy, pandas, and scipy.
I hope this helps!