Skip to Content
Author's profile photo Muhammad Altaf

Getting Started with Python on SAP HANA XSA

It’s Subhan here, a summer intern working on the SAP HANA Product Management team. I’ll be walking you through how to develop Python applications with XSA. Some previous Python knowledge would be great to have, but I will explain everything in detail as we go along!

As for my setup, I am using SAP HANA Express Edition running on an openSUSE Linux machine which I am connected to through VMWare. If you don’t have SAP HANA installed, you can download SAP HANA Express for free and recreate examples from this blog on your own system. I have already installed XSA on my Linux VM as well. If you don’t have XSA installed and configured yet, you can follow the steps at this blog to do so. For all Python development, I am using Microsoft Visual Studio Code on my Windows 10 machine. You can use Linux for development as well. I just prefer using Windows instead.

Currently, XSA only distributes a build pack for Python while the runtime needs to be installed manually by the developer. This is different from Node.js and Java for which XSA provides runtime as well. Similarly, the SAP Web IDE for SAP HANA, the main development IDE for XSA, only supports Java and Node.js development. All Python development needs to be done and deployed through command line interface (CLI).

Setting up Python Runtime

First off, let’s start with deploying the Python runtime to XSA. Using the Terminal on your VM, navigate to a local directory and download and unzip the latest Python source release.

cd /local/dir
tar xzvf Python-3.6.5.tgz
cd Python-3.6.5

Create a new directory to hold compiled Python files and run build.

md name_of_new_dir
./configure --prefix=/path/to/new/directory --exec-prefix=/path/to/new/directory --enable-optimizations
make -j4 && make altinstall

If the process is successful, there should be bin, include, lib, lib64, and share folders created within your new directory.

Figure 1: Command Line Output for Successful Build

At this point, you should be all set to deploy the Python runtime to XSA. However, if you go ahead and do that, the runtime would get deployed fine but every time you try deploying and running an application, it would fail with the following error:

Figure 2: Error Received on Application Deployment

It turns out that if you are using openSUSE LEAP, like myself, instead of the Enterprise SUSE, you have to do a bit more work to have the runtime deployed properly. You need to go into the new directory where you stored Python build and copy contents of the lib64 folder to the lib folder. This step should help prevent errors in deploying your Python applications later and hopefully, save you from the trouble I had to go through!

cp -avp lib64/* lib

Now you are ready to deploy the Python runtime to XSA, for real this time! If you have not done already, start XSA and login as admin using the user XSA_ADMIN and the HANA Express master password you chose when you installed HANA Express. When prompted for a space, choose development.

cd /usr/sap/HXE/HDB00
./HDB start
xs login

Figure 3: Expected Output After Login

Once you are logged in, deploy the Python runtime using xs create-runtime. The path specified should be to the new directory you created to store compiled Python files.

xs create-runtime -p /path/to/compiled/python/directory

To confirm the runtime has been deployed correctly, execute xs runtimes. The output list should include a python3.

Figure 4: Console Output if Runtime Deployed Properly

Ta da! If that’s the output you get, you have successfully deployed a Python runtime to XSA and are ready to start making some awesome, powerful, and yet relatively simple Python applications!

Hello World Application

Now that your Python runtime is all set up, you are ready to build your first application to test the runtime. I will cover everything from now on using Windows, though if you prefer to use Linux instead, all the steps and commands are similar. I will point out any differences as needed.

Create a new directory called pyapp and use this as the root directory for your application. Create a new file called runtime.txt and specify the version of Python runtime you have deployed.

>>> runtime.txt

Create a new file called requirements.txt. This file is used to specify all the dependencies for your python application, similar to the package.json file used in Node.js. As your application gets deployed, XSA goes through this file and gathers the dependent packages using pip, unless the packages are already installed and included in the application folder. Pip is the Python equivalent of npm in Node.js. For this example, we only need to import Flask which is a micro web framework for Python. It is quite simple to use, yet very powerful and useful in executing HTTP operations and designing RESTful APIs.

>>> requirements.txt

Create another file called manifest.yml, which outlines details about your application and its deployment in XSA. This is the application descriptor file similar to the mta.yaml file used for development on the SAP Web IDE for SAP HANA. As I mentioned earlier, you cannot use the Web IDE to build or run Python applications. All Python development has to be done locally and deployed to the XSA server using xs push from the CLI. The downside of this approach is that xs push command cannot run Multi-Target Applications (MTA). It follows the pure Cloud Foundry approach where the manifest is required and only a single module is run at a time. The MTA concept has been added to the Cloud Foundry by SAP, but is not yet available for Python. In short, you have to use a manifest.yml file as opposed to a mta.yaml file for developing Python applications. To read more about how the manifest file is used to deploy applications, follow this link.

>>> manifest.yml
- name: pyapp
  host: pyapp
  path: .
  command: python

Be extremely careful with indentation in the manifest.yml file. Use spaces instead of tabs and make sure similar sections are indented equally. The file conventionally starts with three dashes. The “applications:” line is not indented. The application name is preceded by preceded by a dash and a space. Every subsequent line is indented two spaces and every nested block is indented another two spaces.

Create a file called, which will contain the application logic. Copy and paste the following code into the file. This code snippet initializes a Flask application, assigns it a port to run on, and binds the hello function to the default URL using the route() decorator. You can use @app.route(<URL (without hostname)>) to redirect users to a specific function in your Python application whenever that URL is requested. To read more about how Flask works, visit this link.

import os
from flask import Flask

#create an instance of Flask
app = Flask(__name__)

#assign the port that the flask application runs on
port = int(os.environ.get('PORT', 3000))

#execute hello function when page URL is loaded
def hello():
    return "Hello Python World"

if __name__ == '__main__': 

Save all files and open the command line tool (on Windows or Linux – depending on where you are saving all the files). Login to XSA, make sure you are in the development space, and push the pyapp application to XSA server as shown.

xs login
xs target -s development	    //to change space to development
cd C:/path/to/app/directory
xs push pyapp

If the application is staged and started successfully, the output should display information about the application including the URL to access it.

Figure 5: Console Output on Successful Application Deployment

If you are using hostname based routing, like myself, you will have to set up a host alias to be able to access the application URL (highlighted in Figure 5 above). I should mention here that we, at SAP, do highly recommend using hostname based routing as opposed to port based routing to make applications more user friendly. To set up a host alias, copy the URL for the application. Open the hosts file usually located in C:\Windows\System32\drivers\etc with Visual Studio Code as an administrator. Map the application’s URL to your machine’s IP address as shown below. Again, this step is not necessary if you are using a port based routing.

Figure 6: Host File Containing Hostname Aliases

Open the application URL on a web browser and the output should be “Hello Python World”.

Figure 7: Application Output

Congratulations, you have successfully deployed a Python runtime to XSA and used it to run your first Python application! If you have any trouble following along with any of the steps or run into errors that haven’t been accounted for in this post, feel free to comment below! I really hope you find this post helpful.

You can follow my next blog post here, in which I cover how to connect your applications to XSA services and make use of SAP HANA database connectivity within your application logic.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Tarun Jain
      Tarun Jain

      Hi Subhan,


      I am getting following error "No acceptable C compiler found in $PATH when installing" 

      during build with following step.


      ./configure --prefix=/path/to/new/directory --exec-prefix=/path/to/new/directory --enable-optimizations





      Author's profile photo Muhammad Altaf
      Muhammad Altaf
      Blog Post Author

      Hi Tarun,

      Without knowing much about your system, it seems that you either don't have gcc installed or it is not in your $PATH variable. gcc is used to compile C++ modules that are part of Python. What you can do is either try using a Python distribution that supplies compiled libraries (i.e. Anaconda) or install gcc on your computer.

      You can refer to this thread for help as well:

      Let me know if that doesn't solve the problem or if you have any other issues.


      Author's profile photo Tarun Jain
      Tarun Jain

      Thanks Subhan, It seems something messed up with my $PATH variable, I tried to install gcc using the steps mentioned at given link, but again failed with same error ( refer attached screenshot).

      I was able to install Anaconda, but it failed to execute due to some conflicting version of existing Python 2.7.14 ( not sure how it got installed, I am using the predefined image of SAP HANA, express edition, from  Google Cloud Platform Launcher ) .

      I am  able to run programs with existing Python 2.7.14 , I will try creating a sample xsa application with this run time.




      Author's profile photo Muhammad Altaf
      Muhammad Altaf
      Blog Post Author

      Hi Tarun,


      Before I try anything else, can you please verify that gcc is in your path? (run which gcc and check its path is included in $PATH)




      Author's profile photo Arman Avetisyan
      Arman Avetisyan

      Hi Subhan,


      Is it possible to use Django framework instead of the flask?



      Author's profile photo Muhammad Altaf
      Muhammad Altaf
      Blog Post Author

      Hi Arman,

      I haven’t tried Django myself. I am not completely sure if it would work without any issues or not. I can look more into it and let you know if I find more details!



      Author's profile photo Sai Giridhar Varanasi
      Sai Giridhar Varanasi

      Thank you so much for this wonderful blog Subhan. I will try this out and post queries or questions if any. Python + XSA is exciting!!!

      Author's profile photo Artem Sharganov
      Artem Sharganov

      Hello, thanks for this great tutorial,


      I have a strange problem after creating Python runtime (installing all python requirements, some of the system libs updates), webide service starts crashing. Does anyone face this problem?

      Author's profile photo KANDARP JOSHI
      I was working on installing the Python runtime in XSA. The installation was completed successfully. But when I am trying to run the "Hellow World" Example, I am gettign below error. Can yo uplease help with this?
      Error reads as: PIP is not installed. It is expected to be a part of provided Python Runtime.
      FYI - We have PIP installed and it shows up when we indivudually run it. 





      Author's profile photo Denys van Kempen
      Denys van Kempen

      Great blog, Muhammad.

      For those interested, we have uploaded a video tutorial about creating the/a Python runtime for XSA.

      For the code samples, see


      Denys / SAP HANA Academy

      Author's profile photo Yasmin Valencia
      Yasmin Valencia

      Thanks for the great tutorial.


      I am new to python scripting and I want to try a python script which do xs ups/cups and XSA restart command in my script, but connecting to XSA remotely from a different linux server. It would be great if you can suggest me way to connect remotely xsa from python script.






      Author's profile photo Andrey Pervushin
      Andrey Pervushin

      Hello Muhammad,

      thank you for the interesting guide! But can we do the same using Web IDE?


      Author's profile photo Jingjing Liu
      Jingjing Liu

      Hello Muhammad,

      according to your guide, I created my first python helloWorld application. When I tried to deploy it on the xsa using “xs push”, I got the following error massage:

      OSError: [Errno 8] Exec format error

      The code was downloaded from here. Our python runtime version is 3.8.6. Hana we are using 2.0 SPS04. 

      What could cause this error, would you please help?

      Thank you and best regards