In this article
This new tool allows you to run your own custom code. This feature is useful for performing calculations, generating values, or interacting with queries and components. This step executes your Python code in an isolated environment and passes the results further along the workflow. If you prefer working with JavaScript, use the JavaScript Code tool instead.
How the tool works
- To add a Python сode tool to your automation, add an action and select Python.

- First, you need to configure Input Data. This means you create variables, name them, and define which values to assign to each one. These variables can then be used in your code, along with any new variables you define within the script.

For each variable, you need to:
- Define a name.
- Specify the data type.
- Select a value from the previous steps.
- To add more variables, click Add field. This will create a new row where you can specify the variable name and configure its value. You can delete any extra variables (fields) if needed.

- Then, you configure Output Data. Here, you manually specify the name and type of any variables you want to get as output. In the following steps of your automation, you’ll be able to use the fields you've defined in this section.
Configuring the Output Data is mandatory, even if you didn’t create any new variables in the code.

If the Output Data field is defined in the Output data settings, your code must include the line:
Outputdata = ...
Without this assignment, the step will fail.
- After that, you can write any Python code using the variables you've declared or create new ones based on them.
Albato cannot guarantee the performance of your custom code and is unable to provide support for it. Please use this tool only if you feel confident working with Python.
The code runs in an isolated sandbox environment.
To ensure safe execution, we have restricted external requests and any network operations. For example, libraries used for **HTTP requests** can not be used. You can find the full list of limitations and available modules below.
- In the following steps, you’ll see those same fields you configured in the Output Data section and will be able to use them throughout your automation.
Limitations and Safety
- Python version: 3.11
- Environment timezone: UTC
- Memory limit: 512 MB
- Maximum execution time per step (timeout): 10 seconds
- Code execution: runs in an isolated sandbox environment.
Within the current implementation:
- Installing external libraries is not allowed. Only modules from the whitelist (see below) are available.
- External requests and any network operations are blocked (e.g., requests, urllib, socket).
Whitelist of Modules
The Python step provides access only to modules from the approved whitelist. The following modules, among others, are allowed:
Errors and Diagnostics
If the step fails:
- Check whether Output data is configured correctly and whether output variable names match the names you assign in your code.
- Verify the input data: ensure that the structure or number of lines is sufficient. Many errors occur after split when the input string does not contain the expected lines.
- Make sure you are not using restricted modules or performing network requests.
Examples of Python code tool
Case 1. Subtracting Start DateTime from End DateTime and returning the result in minutes
This use case is helpful when you need to calculate the duration of something, for example, order processing time, call duration, or the length of a meeting. Many services provide two timestamps but do not return the actual difference, so you have to compute it manually. With Python, you can easily convert two dates into a single numerical value and use it later in your automation for filtering, reporting, cost calculations, or analytics.
Code:
from datetime import datetime date_start = datetime.fromisoformat(date_start) # or another format in which the string arrives date_end = datetime.fromisoformat(date_end) dif_minutes = (date_end - date_start).total_seconds() / 60

Case 2. Splitting a DateTime into separate Date and Time values + trimming seconds
Some apps require date and time as separate fields, or you may need to write them to Google Sheets/CRM in a specific format without seconds.
This use case is helpful when:
- the service returns a “messy” date (Unix, ISO, or a raw string);
- you need to compare dates using only hours and minutes;
- you want to standardize the date format for the next automation steps.
- In this example, we split the incoming DateTime value into two fields, date and time, and trim the seconds, keeping only the HH:MM format.
Code:
from datetime import datetime
date_time_str = date_time.strip() # input is ALWAYS a string
if date_time_str.isdigit():
dt = datetime.fromtimestamp(int(date_time_str) / 1000)
else:
try:
dt = datetime.fromisoformat(date_time_str)
except ValueError:
dt = datetime.strptime(date_time_str, "%Y-%m-%d %H:%M:%S")
def date_edit(arr):
return [(f"0{el}" if el < 10 else str(el)) for el in arr]
date_str = ".".join(date_edit([dt.day, dt.month, dt.year]))
time_str = ":".join(date_edit([dt.hour, dt.minute]))

Case 3. Cleaning HTML tags from an email body
Some services send emails or notifications in HTML format, with tags, extra spaces, or unnecessary line breaks. If this data is used later in your automation, for example, sent to a task, Slack, CRM, or to a client, it may look messy and can even break the formatting.
import re
regexp = re.compile(r'<(\/?[^>]+)>|(\n)|(\s{4,})', flags=re.MULTILINE)
html = regexp.sub('', html).strip()

You can now use the Run Python Code tool for calculations, data transformation, and text cleaning inside your automation. If you have any questions, feel free to reach out to our support team in the chat.













