Python 2 or 3 Script
Use the Python Script plugins to quickly manipulate data. All Python plugins only have one action: run an arbitrary function that you configure. Feed the function any JSON objects, including output objects from previous steps in the workflow.
InsightConnect supports both Python 2 and 3, so you can work with whichever version you prefer or are more comfortable with. Both plugins include the following third-party Python libraries:
Set Request Timeouts
Set a timeout value when making requests to external servers in case the server isn't responding in a timely manner. Without a timeout value, your code may hang for several minutes or more because requests don't time out unless you explicitly set a value. Hanging code can be an issue for frequently used plugins, and plugins used by multiple workflows. The plugin may become unresponsive to new jobs because it's stuck waiting for incomplete jobs. The following Requests documentation provides more details on how to set timeout values: https://2.python-requests.org/en/master/user/advanced/#timeouts.
Setup a Python Plugin
When creating a new step in the Workflow Builder:
- Choose Action Step.
- Search for “Python Script 2” or “Python Script 3,” depending on your preference.
- Click on the plugin of your choice, then click Continue.
- Click on Run function, then click Continue.
- In the Configure Details panel, type in your desired Action name.
- Check the box if you want the workflow to continue running even if this step fails.
Configure the <code>run</code> Function
First, pass in JSON objects created by previous steps to the function through the Input field, then customize how the function manages input and output directly in the run function. Learn how to format JSON input here.
To customize the
- Create any local function variables if needed. You can set these to JSON objects or values of other available data types.
- Pass in input variables with built-in method
runfunction uses the key names created by your JSON input to run Python script on your desired variables. To call these variables, add the key name enclosed by double quotes, like
- Create and format output variables in the return statement. Each return variable key must be enclosed in single quotes. To assign values to these variables, follow each key with a colon and the desired output value. These output values can be one of four things:
- Local function variables by name
- Strings, enclosed in double quotes
- Click anywhere outside the Function field to close the editor.
Logging messages To log messages with the Python plugin, import logging and call logging.info() or other logging methods in the run function. print or equivalent statements will not successfully log messages due to how output is handled by the plugin.