Skip to main content

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:

LibraryDescription
numpyA library for working with arrays, matrices, and numerical operations.
bsonA library for encoding and decoding Binary JSON (BSON) format.
pandasA library for data manipulation and analysis, using data structure called DataFrame.
scipyA library for scientific computing, including optimization, stats, and signal processing.
python-pdfA library for generating and manipulating PDF files.
charset-normalizerA library for character encoding detection and normalization.
python-dateutilA library for parsing, formatting, and manipulating dates and times.
cryptographyA library that provides cryptographic recipes for encryption, hashing, and digital signatures.
pyyamlA library for parsing and generating YAML (Yet Another Markup Language) files.
pytzA library for converting and working with time zones.
rsaA library for working with RSA encryption and decryption.
protobufA library for serializing and deserializing data using Google's Protocol Buffers (protobuf) format.
pillowA library for loading, processing, and saving images in various formats.
packagingA library for version handling and packaging of Python projects.
jinja2A library for generating complex text files on-the-fly using a template-based syntax.
markupsafeA library for secure handling of untrusted strings for use with Jinja2 templates.
async-timeoutA library for setting timeouts on asyncio tasks.
beautifulsoup4A library for parsing HTML and XML, and screen-scraping web pages for data.
openaiA library for interacting with OpenAI's API, providing access to AI models like GPT-3 for text completion.
requestsA library for making HTTP requests to APIs and web services.
AsyncioA library for creating asynchronous programs with coroutines and asynchronous I/O.
matplotlibA library for creating 2D and 3D plots, charts, and visualizations.
seabornA data visualization library based on Matplotlib that provides statistical graphics.
tabulateA library for generating pretty table output from lists, tuples, or dictionaries.
jsonA library for encoding and decoding JSON (JavaScript Object Notation) files.
datetimeA standard library module for working with dates and times.