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:
Library | Description |
---|---|
numpy | A library for working with arrays, matrices, and numerical operations. |
bson | A library for encoding and decoding Binary JSON (BSON) format. |
pandas | A library for data manipulation and analysis, using data structure called DataFrame. |
scipy | A library for scientific computing, including optimization, stats, and signal processing. |
python-pdf | A library for generating and manipulating PDF files. |
charset-normalizer | A library for character encoding detection and normalization. |
python-dateutil | A library for parsing, formatting, and manipulating dates and times. |
cryptography | A library that provides cryptographic recipes for encryption, hashing, and digital signatures. |
pyyaml | A library for parsing and generating YAML (Yet Another Markup Language) files. |
pytz | A library for converting and working with time zones. |
rsa | A library for working with RSA encryption and decryption. |
protobuf | A library for serializing and deserializing data using Google's Protocol Buffers (protobuf) format. |
pillow | A library for loading, processing, and saving images in various formats. |
packaging | A library for version handling and packaging of Python projects. |
jinja2 | A library for generating complex text files on-the-fly using a template-based syntax. |
markupsafe | A library for secure handling of untrusted strings for use with Jinja2 templates. |
async-timeout | A library for setting timeouts on asyncio tasks. |
beautifulsoup4 | A library for parsing HTML and XML, and screen-scraping web pages for data. |
openai | A library for interacting with OpenAI's API, providing access to AI models like GPT-3 for text completion. |
requests | A library for making HTTP requests to APIs and web services. |
Asyncio | A library for creating asynchronous programs with coroutines and asynchronous I/O. |
matplotlib | A library for creating 2D and 3D plots, charts, and visualizations. |
seaborn | A data visualization library based on Matplotlib that provides statistical graphics. |
tabulate | A library for generating pretty table output from lists, tuples, or dictionaries. |
json | A library for encoding and decoding JSON (JavaScript Object Notation) files. |
datetime | A standard library module for working with dates and times. |