How to Use Python Code in Albato

How to Use Python Code in Albato
By Elena Krasnoslobodtseva ·
11/27/2025
·
4 min. read

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

  1. To add a Python сode tool to your automation, add an action and select Python.

phytoncode2.png

  1. 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.

phytoncode3.png

For each variable, you need to:

  • Define a name.
  • Specify the data type.
  • Select a value from the previous steps.
 
  1. 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.

phytoncode5.png

  1. 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.

phytoncode6.png

Rule

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.
  1. After that, you can write any Python code using the variables you've declared or create new ones based on them.
Important

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.
  1. 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:

string, re, math, cmath, statistics, random, datetime, calendar, collections, collections.abc, functools, itertools, operator, heapq, bisect, array, copy, json, numpy, csv, base64, binascii, hashlib, hmac, pprint, textwrap, uuid, typing, dataclasses, traceback, decimal, fractions.
 

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
  

phytoncode7.png

 

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]))
  

phytoncode10.png

 

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()
  

phytoncode8.png

 

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.


Elena Krasnoslobodtseva
Content Manager at Albato
All articles by the Elena Krasnoslobodtseva
Writes step-by-step guides for users

Join our newsletter

Hand-picked content and zero spam!

Related articles

Show more
How SaaS Businesses Improve Retention Using AI-Powered Email Marketing
5 min. read

How SaaS Businesses Improve Retention Using AI-Powered Email Marketing

Learn how SaaS brands can use AI-powered email automation to increase retention, reduce churn, and drive engagement with experts from Albato and UniOne.

Paragon Vs. Prismatic Vs. Albato Embedded: Which to Choose
5 min. read

Paragon Vs. Prismatic Vs. Albato Embedded: Which to Choose

Compare Paragon, Prismatic, and Albato Embedded—three leading embedded iPaaS platforms for SaaS. See how they differ in features, UX, pricing, and scalability.

AI for Customer Service Automation with Albato
5 min. read

AI for Customer Service Automation with Albato

Learn how AI agents and Albato automate customer service workflows—from ticket triage to WhatsApp replies and CRM updates.

Prismatic Vs. n8n Vs. Albato Embedded: Full Comparison
4 min. read

Prismatic Vs. n8n Vs. Albato Embedded: Full Comparison

Compare Prismatic vs n8n Embedded vs Albato Embedded—three leading embedded iPaaS solutions—for features, pricing, UX, developer experience, and scalability.

How AI-Driven Copilots Transform Sales: Insights from Albato & Amplemarket
5 min. read

How AI-Driven Copilots Transform Sales: Insights from Albato & Amplemarket

Learn about how AI-driven sales copilots boost productivity, automate workflows, and drive revenue growth based on webinar insights.

How TimelinesAI Supercharged Their Automation Platform with Albato Embedded
2 min. read

How TimelinesAI Supercharged Their Automation Platform with Albato Embedded

TimelinesAI Partners with Albato Embedded to Bring Scalable Automation to WhatsApp and CRM Workflows.

Boost Your Team's Productivity: Less Busywork, More Impactful Decisions
3 min. read

Boost Your Team's Productivity: Less Busywork, More Impactful Decisions

Tools, tips, and tricks to help your team do less busywork and make every decision count.

n8n vs Zapier vs Albato: Best Automation Tool in 2025
8 min. read

n8n vs Zapier vs Albato: Best Automation Tool in 2025

Compare n8n, Zapier, and Albato — top no-code automation tools for freelancers, marketers & sales pros. See features, pricing, and key differences.

Merge Vs. Paragon Vs. Albato Embedded: Best Embedded iPaaS 2025
8 min. read

Merge Vs. Paragon Vs. Albato Embedded: Best Embedded iPaaS 2025

Compare Merge, Paragon, and Albato Embedded — leading embedded iPaaS platforms for SaaS founders. See features, pricing, and best use cases.

How to Connect SerpAPI to Albato
4 min. read

How to Connect SerpAPI to Albato

Connect SerpAPI with Albato to integrate it with over 1000+ apps, including AI tools like Grok and Claude.

How to Connect Nimble to Albato
3 min. read

How to Connect Nimble to Albato

Connect Nimble with Albato with 1000+ other apps, including AI tools like ChatGPT and Grok.

How to Connect Salesmate to Albato
4 min. read

How to Connect Salesmate to Albato

Connect Salesmate to Albato, you can integrate it with over 1000+ apps, including AI tools like ChatGPT and Claude.