Server-side Python

In this case the Pyhon Interpreter environment is installed on the server side where the Xplain Object Analytics Engine is running. This setup enables user to run python code to access Xplain API without installing Python environment and python packages locally.

Benefit

  • Python environment and installed packages can be managed by system admin

  • OS level processing possible, like file /DB access on server

  • faster than Web Assembly

Risk

  • Python is a very powerful language, it can cause serious impact by malicious or bad implementation.

  • the right version of python and installed python packages must fit tog, an unintentional upgrade might cause compatibility problems which could prohibit the code running .

Prerequisites

  1. Python 3.8+ and pip is installed on the server where Xplain Object Analytics Backend is running

  2. required packages like xplain is installed on server via pip .

  3. Xplain Object Analytics engine ist started with application property xplain.serverside.python=true

{% hint style=”info” %} To start Object Analytics Engin with server side python enablement, you could

add the following entry into the external application.properties file

xplain.serverside.python=true

{% endhint %}

{% hint style=”info” %} another option is start the application with addtional JVW parameter

java -jar xoe.jar ..... --xplain.serverside.python=true
 Python Code on Serverside

{% endhint %}

Define Python code to run on server side

Only users with admin role can implement the python code and specify if the code should be performed on server side. Without the explicit serverside checkbox setting, the python code will performed by default in the secure Web Assembly environment

  1. open Python IDE as admin user

  2. add source code or chose the existing python source code,

  3. select the checkbox “serverside”, this checkbox is only visible if user has admin role and backend is started with application property xplain.serverside.python=true (see Prerequisites above)

Install required python packages

If your code requires additional python packages, they can be installed on server side on demand, just add the name of packages in the input field “pip install” , multiple package names can be separated with commas.

The required package information will be persisted together with source code.

Add options to Python code

Python code can be run with multiple additional options, the option values can be consumed in the python code. Options can be specified in the Options field of Python IDE. Source code can be saved with option values.

Example: Define and read options in Server-side Python

Define Options

We could provide multiple options in the input field “Options”, separated by spaces.

Options Syntax: --<option_name>=option_value

Example: How to read option values in server side python source code

import argparse

parser = argparse.ArgumentParser() 
args = parser.parse_args()

age = args.age
region = arges.region