Python

Allows execution of Python running on the IronPython engine with full access to .Net Core functionality.

Usage

You can use the Python Node to run Python code dynamically in Sanbox. Python scripts are running against the IronPython engine for .Net Core. Using the Python Node, you have access to all .Net Core functionality.

Sanbox Access From Code

Functionality is provided to access node input and variables inside your Python script. The following members are exposed:

Name

Description

input

Variable containing input for the Python Node. (If you are using a Python script elsewhere in Sanbox, this value will pertain to something else).

set_scoped_variable(variable_name, data)

Sets a Workflow variable with data. You should insure the variable has been declared in the Designer in order to access it elsewhere.

get_variable(variable_name)

Retrieves a variable by a specified name. Returns nothing if the variable doesn't exist.

Using The Standard Python Library

Most of the Standard Python Library is available. Some Python modules that require C extensions are available, while others are not. This is due to the fact that such modules have to be re-implemented for IronPython.

Coding Against Node Input

To access node input, use the input variable, consider the following Python script:

import clr
import System
clr.AddReference("System.Net")
clr.AddReference("System.Linq")
clr.AddReference("Newtonsoft.Json")
clr.ImportExtensions(System.Linq)
input.firstName + " " + input.lastName

Supplied with this data as input to the Python Node:

{
"firstName": "John",
"lastName": "Smith"
}

Outputs the following string:

"John Smith"

Here is an example of a more complex script. Consider the following data supplied as Input to the Python Node:

{
"menu": {
"header": "SVG Viewer",
"items": [
{
"id": "Open"
},
{
"id": "OpenNew",
"label": "Open New"
},
null,
{
"id": "ZoomIn",
"label": "Zoom In"
},
{
"id": "ZoomOut",
"label": "Zoom Out"
},
{
"id": "OriginalView",
"label": "Original View"
},
null,
{
"id": "Quality"
},
{
"id": "Pause"
},
{
"id": "Mute"
},
null,
{
"id": "Find",
"label": "Find..."
},
{
"id": "FindAgain",
"label": "Find Again"
},
{
"id": "Copy"
},
{
"id": "CopyAgain",
"label": "Copy Again"
},
{
"id": "CopySVG",
"label": "Copy SVG"
},
{
"id": "ViewSVG",
"label": "View SVG"
},
{
"id": "ViewSource",
"label": "View Source"
},
{
"id": "SaveAs",
"label": "Save As"
},
null,
{
"id": "Help"
},
{
"id": "About",
"label": "About Adobe CVG Viewer..."
}
]
}
}

With this script:

import clr
import System
clr.AddReference("System.Net")
clr.AddReference("System.Linq")
clr.AddReference("Newtonsoft.Json")
clr.ImportExtensions(System.Linq)
input.menu.items[1].label

Outputs the following string:

"Open New"

Workflow Variables

The following code will retrieve a variable defined in your Workflow.

myVar = get_variable("myVar")

The following code will set a variable in your Workflow with data:

class person:
firstName = "John"
lastName = "Smith"
set_scoped_variable("myVar", person)

Custom Python Modules

Configured In Sanbox Runtime

You can include your own Python modules (pure Python, no C extensions for any dependencies) by placing the module and its dependencies under the Scripting.PythonModulesPath path configured in the Runtime Config. The default value for the Python modules path is the PythonModules directory located in the Runtime's working directory.