Notes on using Python
The Python core connector offers a single operation:
Execute Script: Executes Python code
Although the connector offers just one operation, it's important to consider some key points before using it.
To grasp the fundamental concepts of the Python script connector, let's examine a scenario whereby data from a Webhook trigger and an Object helper are concatenated.
The workflow is receiving
The
itemName
data from the Webhook trigger{ "itemName": "Sauce Labs Backpack" }
The
itemDescription
from the object helper.{ "itemDescription": "carry all the things with the sleek, stream lined Sly Pack that melds uncompromising style with unequaled laptop and tablet protection." }
Using the following script the workflow concatenates the data:
1'''2You can reference the input variables using input["NAME"]3'''4def executeScript(input):5itemName = input ["itemName"]6itemDescription = input ["itemDescription"]78concatenated_string = itemName + ":" + " " + itemDescription910return concatenated_string11
Now let's understand the steps involved one by one:
Building the scriptCopy
def executeScript(input):
The line marks the beginning of a function definition. The function is namedexecuteScript
and takes one parameter,input
. The function's purpose is to process the input data, execute specific operations on it, and subsequently provide the resulting output.Input variables: Within the function, the values of the variables
itemName
anditemDescription
are extracted from the input dictionary using their corresponding keys.For detailed information, refer to the Input Variables section below.
return statement: The content returned within the script dictates what is accessible for subsequent connector steps to utilize. For example,
return concatenated_string
.In certain scenarios, you may require the use of supported modules in your script, such as
itertools
. However, there's no need to import them explicitly as this will lead to an error message.Make sure to indent your code properly. Python uses indentation to define the scope of statements, such as those within loops, conditionals, functions, and classes.
Input variablesCopy
To access the data provided to the script, we first define variables to hold this data.
In the example below, we define two variables, itemName
and itemDescription
, which will be used to store the data received from the Webhook trigger and object helper, respectively.
By specifying the keys itemName
and itemDescription
, the script retrieves the corresponding values assigned to those keys within the input
dictionary.
itemName = input["itemName"]
itemDescription = input["itemDescription"]
Built-in Feature supportCopy
Python connector's V1.0 supports all of the in-built functionality for Python v3.8 excluding the following:
Python's Format function is not permitted as it is not in alignment with the purpose of the connector itself.
Since only direct scripting is supported with the connector, Class definitions are not possible.
Python connector's V2.0 supports all of the in-built functionality for Python 3.11 excluding the following:
Supported ModulesCopy
The following modules are supported from V2.0:
Modules | Description | Non-supported Methods |
---|---|---|
Mathematical functions defined by the C standard | ||
Mathematical functions for complex numbers | ||
Generate pseudo-random numbers | ||
Provides functions for calculating mathematical statistics of numeric (Real-valued) data | statistics.covariance(x, y), statistics.correlation(x, z, method='ranked') statistics.linear_regression(x, z) | |
Provides support for rational number arithmetic | __floor__() __ceil__() __round__() __format__() | |
Provides support for fast correctly rounded decimal floating point arithmetic | ||
Constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original | ||
Defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers | ||
Provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter | ||
Implements a number of iterator building blocks inspired by constructs from APL, Haskell, and SML | itertools.batched(iterable, n) | |
Exports a set of efficient functions corresponding to the intrinsic operators of Python | ||
Supplies classes for manipulating dates and times | datetime.date.fromtimestamp(timestamp) datetime.date.timetuple() datetime.date.strftime() | |
Allows you to output calendars like the Unix cal program, and provides additional useful functions related to the calendar. | ||
Provides a concrete time zone implementation to support the IANA time zone databas | ||
Implements specialized container datatypes providing alternatives to Python’s general purpose built-in containers, |
Application Scenarios for Supported ModulesCopy
pprint moduleCopy
To view the output in the console, users will need to wrap their pprint
method calls in print
, as shown in the example below:
The pprint
module results are sent to stdout
, which can be invisible to users.
itertools moduleCopy
This example showcases the application of the filterfalse
method from the itertools
module, effectively filtering out even numbers from a list ranging from 1 to 10.
calendar moduleCopy
This example showcases the application of the month
method from the calendar
module. It prints the calendar for March 2024.