Skip to content

Python

This module allows executing custom Python code within a workflow. The user’s code must define a run(data) function that receives the flow data as a Python dictionary. The script runs as an independent Python3 child process, with access to data science libraries like pandas, numpy, and standard utilities like json, datetime, math and statistics. The result must be a Python dictionary that is serialized as JSON. It is ideal for data analysis, advanced numerical processing, or integration with the Python ecosystem.

ParameterTypeRequiredDescription
scriptstringYesPython code that defines a run(data) function. The function receives a dictionary and must return a dictionary.
{
"nextModule": "siguiente_modulo",
"data": {
"suma": 150.0,
"media": 30.0,
"tabla": [
{ "valor": 10, "doble": 20 },
{ "valor": 20, "doble": 40 }
]
}
}
{
"script": "def run(data):\n import numpy as np\n valores = data.get('valores', [])\n return {\n 'suma': float(np.sum(valores)),\n 'media': float(np.mean(valores))\n }"
}
  • Requires Python 3 installed and available as python3 in the system PATH
  • Libraries available by default: json, re, datetime, math, statistics, pandas, numpy
  • If a library is not installed, an error is returned indicating which one is missing
  • Input data is passed via stdin as JSON
  • The result is serialized with json.dumps(result, default=str) to handle non-serializable types
  • The temporary file is automatically deleted after execution
  • If the Python script fails or returns a non-zero exit code, the promise is rejected
  • phpRunner (execute PHP code)
  • executescript (execute JavaScript with access to the workflow context)
  • evaluateExpression (evaluate simple JavaScript expressions)