PROCESIO
OverviewPlatform ActionsIntegrations & DemosMarketplaceCustom ActionsDeveloper’s Guide

Python

Runs your own Python code inside a process and returns its result, its printed output and any error.

The Python action runs a piece of Python code that you write, as one step of your process. Use it for calculations, data clean-up or text processing that no ready-made action covers. The value your code returns becomes an output you can use in the next steps.

Add the action

In the Process Designer toolbox, open Scripting and pick Python (or type Python in the search box).

The Python action properties: Code, Timeout, Single Result, List Result, Stdout and Error

Inputs and outputs

FieldDirectionTypeRequiredWhat to put / what you get
CodeInputText (Python code)YesYour Python code. Use return to send a value back to the process.
TimeoutInputIntegerNoHow many seconds the code may run, from 10 to 180. Default 60.
Single ResultOutputAnyNoThe value your code returns, when it is not a list: a number, text, true/false or an object (a Python dict becomes a JSON object).
List ResultOutputList of anyNoThe value your code returns, when it is a list.
StdoutOutputTextNoEverything your code printed with print().
ErrorOutputTextNoThe error message when your code fails or runs too long. Empty when the code worked.

How your code is run

Your code runs as the body of a function:

  • return <value> ends the code and sends the value to Single Result, or to List Result when the value is a list. Only one of the two is filled.
  • print() does not set a result. What you print goes to Stdout, which is useful for checking what your code did.
  • Code that ends without return leaves both results empty.

Examples

CodeOutput
return 1 + 2Single Result 3
return [1, 2, 3]List Result [1, 2, 3]
return {"name": "Ana", "age": 30}Single Result {"name": "Ana", "age": 30}
print("Hello world")Stdout Hello world, both results empty
raise ValueError("bad value")Error ValueError: bad value (line 1)

You can define functions and call them:

def add(a, b):
    return a + b

print('adding')
return add(2, 3)

Result: Single Result 5, Stdout adding.

A library example:

import pandas as pd
return int(pd.Series([1, 2, 3]).sum())

Result: Single Result 6.

Use process variables in the code

You can insert process variables into the code. Before the code runs, PROCESIO replaces each variable with its value, as plain text. So:

  • a number variable can be used as it is: total = <your number variable> * 2;
  • a text variable needs quotes around it in your code: name = "<your text variable>".

Good to know

  • A failing script does not stop the process. When your code raises an error or runs longer than Timeout, the step still finishes: Error holds the message (TimeoutError for a timeout) and both results are empty. Add a Decisional after the action that checks whether Error is empty.
  • The code runs in a sandbox. It cannot read or write files (open is not available) and some modules cannot be imported, for example os or requests; the error then says import of '…' is not allowed in this sandbox. To call a web API, use Call API or CURL and pass the response to the script.
  • Files: a script cannot take a file directly. Convert the file to text with File To Base64, pass the text to the script and decode it there with base64. To create a file from a script, return Base64 text and convert it with Base64 To File.
  • Heavy libraries such as pandas take a few seconds to load. Keep Timeout well above the time your code needs.

Available libraries

Besides the standard modules such as json, base64, math, re and datetime, these libraries are installed:

LibraryImport as
pandasimport pandas
NumPyimport numpy
SciPyimport scipy
Matplotlibimport matplotlib
Beautiful Soupfrom bs4 import BeautifulSoup
PyPDF2import PyPDF2
pdfplumberimport pdfplumber
spaCyimport spacy
staticmapimport staticmap
Pillowfrom PIL import Image

Python (Old) is the previous version of this action. It has a single Output instead of the separate result, Stdout and Error outputs. It still works in existing processes; use Python for new ones. See Actions to be decommissioned.

On this page