Connecting to HANA Server using Python Programming

      Comments Off on Connecting to HANA Server using Python Programming

In this tutorial, we will see how to connect python applications to use HANA Database.

We need to install PyHDB module in order to have python- HANA related drivers and libraries compatible with the Python.

We need execute the below commands to install pyhdb module in python

Linux – pip install pyhdb

Windows – python -m pip install pydhb

pyhdb installation

once after installation we can import the pyhdb module in python to establish connection with the HANA Database.

import pyhdb

Above line imports the pyhdb module in python to use connection function for the HDB Database

pyhdb.connect(host=”hostname”,port=3XX15,username=”SYSTEM”, password=”password”)

Sample Code in Python to check the Databases:

import pyhdb
conn=pyhdb.connect(
host="hostname",
port=3XX15,
user="SYSTEM",
password="HXXXXX19"
)
cursor=conn.cursor()
cursor.execute("SELECT * from M_DATABASES")
cursor.fetchone()