Skip to content

Python Scripts

Python scripts run using Python 3 in a subprocess. The following packages are pre-installed system-wide:

PackageVersionUse case
pandasLatestData manipulation, CSV/Excel processing
openpyxlLatestExcel file reading and writing

Standard library modules are fully available (json, urllib, datetime, os, re, etc.).

Injected variables

Auth headers and payload are passed via environment variables:

Env variableDescription
AUTH_HEADERSJSON string of auth headers — parse with json.loads()
TASK_PAYLOADWebhook or MQTT payload string (if triggered by one)

Example: call a REST API

python
import json
import os
import urllib.request

auth_headers = json.loads(os.environ.get('AUTH_HEADERS', '{}'))

req = urllib.request.Request(
    'https://api.example.com/users',
    headers=auth_headers
)

with urllib.request.urlopen(req) as resp:
    users = json.loads(resp.read())

print(f"Found {len(users)} users")
active = [u for u in users if u.get('active')]
print(f"Active: {len(active)}")
print(json.dumps(active, indent=2))

Example: process CSV data with pandas

python
import json
import os
import pandas as pd
import urllib.request
import io

auth_headers = json.loads(os.environ.get('AUTH_HEADERS', '{}'))

# Download a CSV report
req = urllib.request.Request(
    'https://api.example.com/reports/daily.csv',
    headers=auth_headers
)

with urllib.request.urlopen(req) as resp:
    df = pd.read_csv(io.StringIO(resp.read().decode('utf-8')))

print(f"Rows: {len(df)}")
print(f"Columns: {list(df.columns)}")

summary = df.groupby('category')['amount'].sum()
print(summary.to_string())

Example: process Excel with openpyxl

python
import openpyxl
import urllib.request
import io
import json
import os

auth_headers = json.loads(os.environ.get('AUTH_HEADERS', '{}'))

req = urllib.request.Request(
    'https://api.example.com/export.xlsx',
    headers=auth_headers
)

with urllib.request.urlopen(req) as resp:
    wb = openpyxl.load_workbook(io.BytesIO(resp.read()))

ws = wb.active
print(f"Sheet: {ws.title}, rows: {ws.max_row}")

for row in ws.iter_rows(min_row=2, values_only=True):
    print(row)

Logging

Python scripts use print() for output — all stdout is captured and shown as INFO level in the run log. Write to stderr for ERROR level:

python
import sys

print("This is INFO level")
print("This is also INFO level")
print("This is ERROR level", file=sys.stderr)