Python Code
Python Code
Runs a block of custom Python code inside the automation flow and returns the output it produces. Ideal for scenarios that need scientific or data-processing libraries, or other features native to the Python ecosystem that are not available in JavaScript.
For this action to work, Python must be installed on the machine the robot runs on.
Options
Code
Write the block of Python code to run. Use print() to define the value the action returns — the captured return is everything printed to standard output while it runs.
Reading the output of previous actions
The Python code runs as a separate process and has no direct access to the flow variables. To pass values from previous actions, use the JavaScript interpolation syntax (${...}) directly in the code — the value is substituted before Python runs:
# The previous action's value is embedded before Python runs
nome = "${actions['lerNome']['value']}"
codigo = "${actions['lerCodigo']['value']}"
print(f"Cliente: {nome} — Código: {codigo}")
For numeric or boolean values, the interpolation works directly:
total = ${actions['calcularTotal']['value']}
print(total * 2)
For objects or lists, use JSON.stringify to serialize and json.loads to deserialize in Python:
import json
dados = json.loads('${JSON.stringify(actions["consultarDados"]["value"])}')
for item in dados:
print(item["nome"])
Reading the robot parameters
Use {{PARAMETROS.name}} to embed a parameter directly in the code:
servidor = "{{PARAMETROS.servidor}}"
print(f"Conectando em: {servidor}")
For secrets (parameters marked as password), use {{SEGREDOS.name}}.
The ${...} syntax is evaluated by JavaScript before Python runs. Python receives the code with the values already substituted — it never sees the ${...}.
Returns
Javascript code
actions["action-id"].value // output produced by the Python code through print (Any)
Field selection
- value — content printed by the Python code while it ran (Any)
Rules and Conditions
- The Code field is required.
- The action's return is the content printed through
print()while it ran. - Python must be installed and correctly configured on the machine the robot runs on.
- Runtime errors in the Python code stop the robot.
Using external libraries
Roberty ships its own Python (version 3.8) and any library can be installed through pip. See the Install external Python libraries tutorial for the full walkthrough.