Execute Python code in workflows

Learn how to write Python code that transforms data and extends functionality in Retool Workflows.

If you're more familiar with Python, you can use it instead of JavaScript to manipulate data. Use Code blocks to write custom Python code that can transform data and perform complex logic. You can also use popular Python libraries to further extend the functionality of workflows.

Add a Python Code block

To use Python in a workflow, add a Code block to the canvas and select Python.

Write and execute Python code

The Python code editor has much of the same features as the JavaScript editor, such as autocomplete and syntax highlighting. For example, you can transform an array of records in a similar manner to map() with JavaScript:

data = query2.data
return [{
   "fullName": customer['first'] + ' ' + customer['last'],
   "emailAddress": customer['email']
} for customer in data]

Python limitations

JavaScript is the primary method for manipulating and transforming data in Retool. To maintain interoperability with other blocks, Python does not support:

  • Function block calls or triggering queries.
  • Usage within Loop and Filter blocks.
  • Data output in types other than serialized JSON.
  • User-imported Python libraries.

Available libraries

Python queries include built-in support for many popular libraries. This enables you to extend the functionality of workflows beyond data transformation. Available libraries include: