Code Execution Node Examples

The Code Execution Node supports running arbitrary Python or TypeScript code to perform data transformations in your Workflow. It can simplify your workflow, especially in cases where a combination of Conditional, Templating, and Merge nodes are used. Below are some example use cases:


Check if a number is a multiple of another

1def main(
2 arg1: int,
3 arg2: int,
4) -> int:
5 # this function returns the multiple if arg1 is a multiple of arg2
6 # or the remainder otherwise
7 if arg1 % arg2 == 0:
8 return arg1 / arg2
9 else:
10 return arg1 % arg2

JSON Manipulation

Remap the keys

1def main(
2 arg: dict
3) -> dict:
4 return {
5 "newKey": arg.get("oldKey", None)
6 }

Code Packages

You can add both pip packages for Python code and npm packages for TypeScript code. You must provide exact package versions and add the import to your code yourself.

Note that whenever you update your packages list, the first execution after doing so may be slow due to our system creating and caching the custom runtime.

1import * as _ from "lodash";
3async function main(inputs: {
4 test: string,
5}): Promise<number> {
6 return inputs.test.length + _.floor(5.452);

Code Package example