Skip to Content

How to connect to SAP HANA database server in Python


How to connect to SAP HANA database server in Python

By Chris-Huston

A How-To that shows how to integrate python with the SAP HANA database server

How-To Details

In many python applications, you would need access to a database for storing, retrieving and other uses of data. In this How-To, you will use a sample database connection program using SAP HANA Client that provides python connectivity to SAP HANA libraries and executables.

  1. Navigate to the path where HANA client is installed and then copy these three files,, By default, the SAP Client is installed at:

    Microsoft Windows :- C:\Program Files\SAP\hdbclient\

    Linux Platform :- /usr/sap/hdbclient/

    python files present in hdbclient directory
  2. Then go to the Python directory under hdbclient directory and paste all three files into the Lib directory.

    Lib directory
  3. Copy pyhdbcli.pdb, pyhdbcli.pyd files from hdbclient directory.

    copy two more files in hdbclient directory
  4. Do the same as step 2 above, paste the files into Python/Lib directory. Now you are done with the configuration part.

  5. In this step, copy and paste the below code in an editor and save the file with the .py extension. In the below example, The port 3< instance number >15 matches to the tenant database named HXE.

    import dbapi
    #Replace with your hostname, unique port for the database you are connecting,
    #UserID and password in that order.
    connection=dbapi.connect('hxehost', 39013, 'system', 'MyPassword')
    #This statement prints true if the connection is successfully established
    print connection.isconnected()
  6. Copy the file into Python directory of HANA Client and execute in the same directory using command


    Or if you are using python IDE, assign python.exe from the same directory as the python executable.

  7. Run the program and if the program prints True, then the connection to SAP HANA database is successful.

Next Steps

Updated 04/05/2017

Time to Complete

10 Min.



Next Steps

Back to top