SQLAlchemy Dialect for SAP HANA
Switch branches/tags
Clone or download
snnowwy and jarus Allow passing of db URL parameters to dbapi (#54)
Query parameters specified in the database URI were not being added to connect_args for the underlying database driver. Therefore it wasn't possible to enable encryption via `?encrypt=true` or other required features for the SAP Cloud Platform offerings.
Latest commit 12e2ec3 Nov 17, 2018

README.rst

SQLAlchemy dialect for SAP HANA

This dialect allows you to use the SAP HANA database with SQLAlchemy. It can use the supported SAP HANA Python Driver hdbcli (supported since SAP HANA SPS 2) or the open-source pure Python client PyHDB. Please notice that sqlalchemy-hana isn't an official SAP product and isn't covered by SAP support.

Prerequisites

Python 2.7 or Python 3.X with installed SAP HANA DBAPI implementation.

SAP HANA Python Driver see SAP HANA Client Interface Programming Reference or the install section of PyHDB.

Install

Install from Python Package Index:

$ pip install sqlalchemy-hana

You can also install the latest version direct from a cloned git repository.

$ git clone https://github.com/SAP/sqlalchemy-hana.git
$ cd sqlalchemy-hana
$ python setup.py install

Getting started

If you do not have access to a SAP HANA server, you can also use the SAP HANA Express edition.

After installation of sqlalchemy-hana, you can create a engine which connects to a SAP HANA instance. This engine works like all other engines of SQLAlchemy.

from sqlalchemy import create_engine
engine = create_engine('hana://username:password@example.de:30015')

Alternatively, you can use HDB User Store to avoid entering connection-related information manually each time you want to establish a connection to an SAP HANA database:

from sqlalchemy import create_engine
engine = create_engine('hana://userkey=my_user_store_key')

You can create your user key in the user store using the following command:

hdbuserstore SET <KEY> <host:port> <USERNAME> <PASSWORD>

By default the hana:// schema will use hdbcli (from the SAP HANA Client) as underlying database driver. To use PyHDB as driver use hana+pyhdb:// as schema in your DBURI.

In case of a tenant database, you may use:

from sqlalchemy import create_engine
engine = engine = create_engine('hana://user:pass@host/tenant_db_name')

Contribute

If you found bugs or have other issues, you are welcome to create a GitHub Issue. If you have questions about usage or something similar please create a Stack Overflow Question with tag sqlalchemy and hana.