See Stacksync in action with a solution architect. Book a demo ↗

Python Code Execution

Run custom Python scripts directly inside your workflow. Use it for data transformation, complex logic, reshaping payloads, or anything that can't be handled by a standard module.

1. Add the Module

Add the Python Code module to your workflow as an action node.

Action modules panel searched for "code execution", with an arrow pointing to "Python Code" under Code Execution.

2. Pass Data In Context

In the module configuration panel, add context variables under the Context section. Each entry takes a Name and a Value, use the variable picker to map values from upstream nodes.

Each context entry becomes a key on WORKFLOW_CONTEXT inside your script:

def main(WORKFLOW_CONTEXT):
    amount = WORKFLOW_CONTEXT["amount"]
Python Code module with a Context entry "amount" mapped to {{ input.body.amount }} and read in the script as WORKFLOW_CONTEXT["amount"].

3. Write Your Script

Your script must define a main function. Stacksync automatically injects WORKFLOW_CONTEXT as the argument containing all your context values.

def main(WORKFLOW_CONTEXT):
    amount = WORKFLOW_CONTEXT["amount"]
    return {
        "amount": amount,
    }

4. Return Data

Whatever main returns becomes the node's output, available to downstream nodes via standard node referencing.

Workflow Execution Logs for a successful run, with the Python Code Execution output returning "amount": 100 highlighted.

Reference in downstream nodes:

{{ module_id.amount }}

Debugging: print() output is captured and surfaced under metadata.stdout in the execution logs. Use it for debugging — it does not pass data downstream.

Available Libraries

LibraryUse case
pandasData manipulation and transformation
numpyNumerical operations
phonenumbersPhone number parsing and formatting
jsonJSON parsing
osOS-level utilities
Python 3.10 standard libraryAll built-in modules

Limits

LimitValue
Timeout300s (5 min)
Memory700 MB
FilesystemRead-only, no writes
Runtime packagesPre-installed only

Watch out: Large pandas DataFrames can hit the 700 MB memory limit. Process data in chunks where possible.

On this page