# Server-side Python mode

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.&#x20;

#### Benefit&#x20;

* 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&#x20;

#### Risk&#x20;

* Python is a very powerful language, it can cause serious impact by malicious or bad implementation.
* &#x20;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[ <mark style="color:blue;">xplain</mark>](https://pypi.org/project/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&#x20;

add the following entry into the external <mark style="background-color:orange;">application.properties</mark> file

```apacheconf
xplain.serverside.python=true
```

{% endhint %}

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

<pre class="language-shell"><code class="lang-shell"><a data-footnote-ref href="#user-content-fn-1">java -jar xoe.jar ..... --xplain.serverside.python=true</a>
 Python Code on Serverside
</code></pre>

{% endhint %}

## Define Python code to run on server side

Only users with <mark style="color:red;">admin role</mark>  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&#x20;

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)

<figure><img src="/files/aKdqez29p92AOA57wbyC" alt=""><figcaption><p>server side python mode, user with admin role</p></figcaption></figure>

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

<figure><img src="/files/mIzryECM5scO1KPnvg0r" alt=""><figcaption></figcaption></figure>

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.&#x20;
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&#x20;

&#x20;

## 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.&#x20;

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

<figure><img src="/files/2IOifiefm3k8hOENDLur" alt=""><figcaption></figcaption></figure>

## 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.&#x20;

### Example: Define and utilise options in Server-side Python mode

#### Define Options

&#x20;We could provide multiple options in the input field "Options",  separated by spaces. &#x20;

Options Syntax: `--<option_name>=option_value`

<figure><img src="/files/m6dDqHCWwRVA0vhTNtgZ" alt=""><figcaption></figcaption></figure>

#### Example: How to read option values in <mark style="background-color:orange;">server side</mark> python source code

```python
import argparse

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

age = args.age
region = arges.region

```

[^1]:


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xplain-data.gitbook.io/community-edition/python-services-overview/python-ide/advanced-topic/server-side-python-mode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
