Differences
This shows you the differences between two versions of the page.
functions:python [2025/01/21 01:59] optrix created |
functions:python [2025/01/21 02:12] (current) optrix |
||
---|---|---|---|
Line 3: | Line 3: | ||
The **python** method is a [[style|function method]] that launches a Python script in response to an API request and returns any information that the script writes to the console. | The **python** method is a [[style|function method]] that launches a Python script in response to an API request and returns any information that the script writes to the console. | ||
- | ===Additional Parameters=== | + | ===Additional |
- | This method requires a **path** parameter - this is the path to the Python script. This path can include [[substitutions|substituions]]. | + | This method requires a **path** parameter - this is the path to the Python script. This path can include [[substitutions|substitutions]]. |
+ | |||
+ | ===Captured Output=== | ||
+ | |||
+ | To allow for diagnostic and debugging messages, the output returned to the user is split by separators. By default, this is a set of four minus-signs (' | ||
+ | |||
+ | If these separators are present in the output of your program, only the text after the **last separator** will be sent. | ||
+ | |||
+ | So in the following output... | ||
+ | |||
+ | < | ||
+ | Hello World | ||
+ | Sending Query.... | ||
+ | Running Analytics... | ||
+ | ---- | ||
+ | Time, Value | ||
+ | 10: | ||
+ | 10: | ||
+ | 10: | ||
+ | </ | ||
+ | |||
+ | ...only the lower half (from ' | ||
+ | |||
+ | If there are no separators found, the system returns the full output of your script. | ||
+ | |||
+ | ===How It Works=== | ||
+ | |||
+ | For this method, the user-provided parameters are converted into a JSON file. The full path of this file is then sent as the first parameter of your script. | ||
+ | |||
+ | For example, the following info.json file... | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }]. | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ...would result in the following steps if it was called with the default parameter values. | ||
+ | |||
+ | ===Building the Input File=== | ||
+ | |||
+ | The following file would be created and saved to a temporary file at **mytempfile.json** (this is a simplified file name for ease-of-reading). | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===Calling the Function=== | ||
+ | |||
+ | The python code would then be run with the following command... | ||
+ | |||
+ | < | ||
+ | python c: | ||
+ | </ | ||
+ | |||
+ | ===Capturing Output=== | ||
+ | |||
+ | The output of the function would then be captured and sent to the user. | ||
+ | |||
+ | In more advanced scenarios, some [[style scripts]] might also be run to help translate the output between formats such as JSON to XML. |