Server-side Python mode

Enterprise only

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

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

another option is start the application with addtional JVW parameter


 Python Code on Serverside

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)

server side python mode, user with admin role

Perform python code on server side as standard user without admin role

  1. python file list : list of the python files

  2. code area: the python code can be edited and viewed there The admins can write comments inside python comment block such as '''description in the comment block''' will be displayed to the users, who do not have the admin right to read the code in the code area.

  3. output area: the output is there

  4. run icon: run the python code

  5. pip install area: install area are automatically filled for the user. Install the packages by entering the package names divided using a "," for example: xplain, panda, streamlit

  6. options: options are set automatically for the user. Multiple options can be set in the input field "Options", separated by spaces. Options syntax: --<option_name>=option_value

  7. collapse icon: collapse the IDE

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.

Apply 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 utilise options in Server-side Python mode

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

Last updated