Remote Python Script

Overview

The Remote Python Script Snap enables you to execute a Python script on a Remote Python Executor (RPE). The RPE can be installed on the same node as the JCC or elsewhere. The location of the RPE is specified in the account. See Remote Python Executor Installation for steps on installing the RPE.


Remote Python Script Snap dialog

Prerequisites

The RPE should be installed and running before using this Snap. See Remote Python Executor Installation for steps to install the RPE.

Limitations and known issues

None.

Snap views

View Description Examples of upstream and downstream Snaps
Input This Snap has at most two document input views.
  • First input view: The document upon which the Python script is to be executed.
  • Second input view: The Python script to be executed.
First input view: Second input view:
Output This Snap has at least one and at most two document output views.
  • First output view: The output from the Python script's execution.
  • Second output view: The STDOUT redirected from the RPE.
First output view: Second output view:
Error

Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the pipeline by choosing one of the following options from the When errors occur list under the Views tab. The available options are:

  • Stop Pipeline Execution Stops the current pipeline execution when an error occurs.
  • Discard Error Data and Continue Ignores the error, discards that record, and continues with the remaining records.
  • Route Error Data to Error View Routes the error data to an error view without stopping the Snap execution.

Learn more about Error handling in Pipelines.

Snap settings

Legend:
  • Expression icon (): JavaScript syntax to access SnapLogic Expressions to set field values dynamically (if enabled). If disabled, you can provide a static value. Learn more.
  • SnapGPT (): Generates SnapLogic Expressions based on natural language using SnapGPT. Learn more.
  • Suggestion icon (): Populates a list of values dynamically based on your Account configuration.
  • Upload : Uploads files. Learn more.
Learn more about the icons in the Snap settings dialog.
Field / field set Type Description
Label String

Required. Specify a unique name for the Snap. Modify this to be more appropriate, especially if more than one of the same Snaps is in the pipeline.

Default value: Remote Python Script

Example: Remote Python Script
Edit Script Button Required.

The Python script to be executed. Click Edit Script to open the script editor. The editor contains a default Python script, edit it as required or supply another script through the second input view.

The default script writes the input documents to the $original field in the output.

Default value: Default Python script as shown below:

Default Python script
#Imports

#Global Variables

#This function will be executed once before consuming the data.
def snaplogic_init():
return None

#This function will be executed on each document from the upstream snap.
def snaplogic_process(row):
output = {}
output["original"] = row
return output

#This function will be executed after consuming all documents from the upstream snap.
def snaplogic_final():
return None

There are three main functions in the default script: snaplogic_init, snaplogic_process, and snaplogic_final.

  1. The first function (snaplogic_init) is executed before consuming input data.
  2. The second function (snaplogic_process) is called on each of the incoming documents.
  3. The last function (snaplogic_final) is processed after all incoming documents have been consumed by snaplogic_process.
Snap execution Dropdown list Select one of the three modes in which the Snap executes.
Available options are:
  • Validate & Execute. Performs limited execution of the Snap and generates a data preview during pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during pipeline runtime.
  • Execute only. Performs full execution of the Snap during pipeline execution without generating preview data.
  • Disabled. Disables the Snap and all Snaps that are downstream from it.