Getting started
Rules Engine Widgets
Run Python
23 min
overview the run python node is a workflow component in simplita ai that allows you to execute python code as part of an automated workflow it provides a secure, sandboxed environment for running python scripts to perform calculations, data transformations, string processing, and custom logic operations think of it as embedding a python execution engine directly into your workflow automation pipeline, enabling complex operations that standard workflow nodes cannot handle component classification node type logic node → custom logic category workflow elements purpose execute python code in secure sandbox runtime environment restricted python sandbox (stdlib only) external packages not supported execution timeout 30 seconds (configurable) key characteristics secure execution code runs in isolated sandbox environment standard library support all python standard library functions available no external dependencies pip packages not supported deterministic output produces consistent results for same inputs error handling captures and reports execution errors result storage output stored in configurable variable run python vs extended python the following table compares the two python execution node types available in simplita ai feature run python extended python execution environment secure sandbox full environment library support standard library only all python packages external packages not available available via pip execution speed fast slower risk level low higher best use case simple operations complex data science memory constraints limited higher limits file system access restricted available component structure and configuration the run python node comprises several key configuration sections input variables section purpose import data from previous workflow steps into python code configuration options add input variable enables selection of data from prior nodes custom variable names allows renaming inputs for code clarity variable list displays all configured input variables usage variables become accessible within python code by their assigned names python code editor section the main code execution area with the following features features syntax highlighting for python code line numbering for error reference auto indentation support code completion suggestions error highlighting constraints maximum execution time 30 seconds memory limit standard runtime constraints sandbox restrictions no system calls or file access output configuration section purpose define where and how execution results are stored configuration elements output variable name default is "pythonresult" result display shows execution output copy result button exports result for use in other nodes execution settings timeout (seconds) specifies maximum allowed execution time (default 30) output detail level controls verbosity of results (basic, detailed, full) available python standard library the run python node supports the following standard library modules data and mathematical operations json json encoding and decoding math mathematical functions and constants statistics statistical calculations decimal precise decimal arithmetic fractions rational number operations random random number generation string and text processing string string utilities and constants re regular expression pattern matching textwrap text formatting and wrapping difflib text comparison utilities collections and data structures collections specialized container types array typed array objects weakref weak object references date and time operations datetime date, time, and timestamp operations calendar calendar functions time time operations encoding and decoding base64 base64 encoding and decoding urllib url parsing utilities hashlib cryptographic hash functions functional programming and utilities itertools iterator operations functools higher order functions operator standard operators as functions not available (requires extended python) pandas data manipulation library numpy numerical computing library requests http client library beautifulsoup4 html parsing library scikit learn machine learning library any third party packages requiring pip installation basic usage guide accessing the run python node step 1 open simplita ai workflow editor step 2 click logic category in left navigation panel step 3 search for "python" or locate "run python" step 4 drag run python node onto canvas step 5 configure node settings in properties panel creating input variables step 1 click "add input variable" button step 2 select data source from previous workflow nodes step 3 assign a variable name for use in python code step 4 click confirm example if previous api call returns user data, create input variable named "user info" writing python code step 1 click python code section step 2 enter python code in editor step 3 reference input variables by their assigned names step 4 ensure code completes within timeout period configuring output step 1 specify output variable name (default pythonresult) step 2 set desired output detail level step 3 execute the workflow step 4 results stored in specified output variable using results in other nodes after execution, reference results in subsequent nodes full result {{pythonresult}} specific field {{pythonresult fieldname}} array element {{pythonresult}} practical code examples example 1 financial calculation \# calculate total price with tax and discount product price = 150 00 tax rate = 0 08 discount percentage = 10 \# calculate discount discount amount = product price (discount percentage / 100) price after discount = product price discount amount \# calculate tax tax amount = price after discount tax rate \# final total final total = price after discount + tax amount \# result summary result = { "original price" product price, "discount applied" discount amount, "price after discount" price after discount, "tax amount" tax amount, "final total" final total, } print(result) example 2 string processing and validation \# process and validate email format import re email input = "user\@example com" \# email validation pattern email pattern = r'^\[a za z0 9 %+ ]+@\[a za z0 9 ]+\\ \[a za z]{2,}$' \# validate email is valid email = bool(re match(email pattern, email input)) \# extract email components email parts = email input split("@") username = email parts\[0] domain = email parts\[1] \# result summary result = { "email" email input, "is valid" is valid email, "username" username, "domain" domain, "upper email" email input upper(), } print(result) example 3 data aggregation and analysis \# analyze sales data sales records = \[ {"product" "widget a", "amount" 150}, {"product" "widget b", "amount" 200}, {"product" "widget c", "amount" 175}, {"product" "widget a", "amount" 120}, {"product" "widget b", "amount" 190}, ] \# calculate total sales by product product totals = {} for record in sales records product = record\["product"] amount = record\["amount"] if product in product totals product totals\[product] += amount else product totals\[product] = amount \# calculate summary statistics total sales = sum(record\["amount"] for record in sales records) average sale = total sales / len(sales records) highest sale = max(record\["amount"] for record in sales records) lowest sale = min(record\["amount"] for record in sales records) \# result summary result = { "total sales" total sales, "average sale" average sale, "highest sale" highest sale, "lowest sale" lowest sale, "product breakdown" product totals, "transaction count" len(sales records), } print(result) error handling and debugging common error types syntax error incorrect python syntax (missing colons, indentation errors) runtime error code runs but encounters issue during execution (division by zero, undefined variable) timeout error code execution exceeds 30 second limit type error incompatible data type operations index error accessing non existent list or string index debugging strategies use print statements add print() at key points to track execution flow print(f"debug variable x = {x}") check data types verify input data types before operations print(type(input variable)) validate input data check for null or unexpected values if input variable is none result = "error input is null"else result = process(input variable) test incrementally build code step by step rather than large blocks implement try except catch and handle specific errors try result = risky operation()except specificerror as e result = f"error occurred {str(e)}" best practices output variable usage the output variable stores execution results for use in subsequent workflow nodes default variable name pythonresult accessing output results full result {{pythonresult}} dictionary field {{pythonresult fieldname}} array element {{pythonresult}} nested value {{pythonresult parent child}} copy result button located in run python node properties copies result to clipboard format suitable for pasting in other nodes reference automatically added to workflow configuration parameters timeout setting default value 30 seconds maximum value 30 seconds purpose prevents infinite loops from breaking workflow effect of timeout if code execution exceeds timeout, node fails with timeout error output detail level basic mode returns result value only detailed mode returns result plus execution metadata full mode returns comprehensive execution information including debug data recommended usage use basic for production, detailed for debugging integration with workflow previous node data input add input variables to import results from prior workflow steps variables become accessible within python code supports complex data structures (objects, arrays, nested data) next node data output store results in output variable with configurable name use output variable in subsequent node configurations results persist throughout workflow execution connection best practices validate input data before processing handle missing or null values explicitly structure output to match downstream node requirements document data format expectations execution flow and lifecycle initialization phase input variables loaded and made available code execution phase python code executes in sandbox output generation phase results stored in output variable timeout monitoring execution terminated if exceeds timeout error capture phase errors recorded and returned if failure occurs