The Python Database API Specification v2.0 (PEP 249) defines a set of methods that provides a consistent database interface independent of the actual database being used. The Python extension module for SAP HANA implements PEP 249.
Once you install the module, you can access and change the information in SAP HANA databases from Python. In PEP 249, autocommit is turned off by default. In the SAP HANA Python driver, autocommit is turned on by default.
The SAP HANA client supports Python 3.4 and later and Python 2.7.
Install the Python driver into your local Python environment by using the pip installer so that you can use the Python driver to connect to an SAP HANA database.
Install via pip install hdbcli
or install manually via the HANA Client Install
You have run the SAP HANA client install.
- If you have multiple Python environments, then activate the Python environment where you want to install the Python driver. If you don’t have multiple Python environments, then ignore this step.
- Run the install:
pip install
pip install "C:\Program Files\SAP\hdbclient\hdbcli-N.N.N.zip"
easy_install
easy_install "C:\Program Files\SAP\hdbclient\hdbcli-N.N.N.zip"
disutils installer
Unzip hdbcli-N.N.N.zip into a directory, then run:
cd hdbcli-N.N.N
Lastly, run:
setup.py install
Use one of the following install methods:
pip install
pip install /usr/sap/hdbclient/hdbcli-N.N.N.tar.gz
easy_install
pip install /usr/sap/hdbclient/hdbcli-N.N.N.tar.gz
disutils installer
tar -xf hdbcli-N.N.N.tar.gz
Then run:
cd hdbcli-N.N.N
Lastly, run:
setup.py install
For HANA tenant databases, use the port number 3NN13 (where NN is the SAP instance number - e.g. 30013).
For HANA system databases in a multitenant system, the port number is 3NN13.
For HANA single-tenant databases, the port number is 3NN15.
from hdbcli import dbapi
conn = dbapi.connect(
address="<hostname>",
port=3<NN>MM,
user="<username>",
password="<password>"
)
cursor = conn.cursor()
Other/Proprietary License (SAP DEVELOPER LICENSE AGREEMENT)