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: requests, maya, lxml, beautifulsoup, pyyaml, and records.

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:

Setup a Python Plugin

When creating a new step in the Workflow Builder:

  1. Choose Action Step.
  2. Search for “Python Script 2” or “Python Script 3,” depending on your preference.
  3. Click on the plugin of your choice, then click Continue.
  4. Click on Run function, then click Continue.
  5. In the Configure Details panel, type in your desired Action name.
  6. 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 run function:

  1. Create any local function variables if needed. You can set these to JSON objects or values of other available data types.
  2. Pass in input variables with built-in method params.get(). The run function 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 params.get(“keyname”).
  3. 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
  • params.get() statements
  • Strings, enclosed in double quotes
  • Numbers
  1. Click anywhere outside the Function field to close the editor.

Logging messages To log messages with the Python plugin, import logging and call 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.