Skip to main content

SAP HANA Python Client

Project description

Introduction

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.

For information, see: PEP 249 – Python Database API Specification v2.0

Getting Started

Install via pip install hdbcli or install manually via the HANA Client Install

Quick Start

  • For HANA tenant databases, use the port number 3**NN**13 (where NN is the SAP instance number - e.g. 30013).
  • For HANA system databases in a multitenant system, the port number is 3**NN**13.
  • For HANA single-tenant databases, the port number is 3**NN**15.
from hdbcli import dbapi
conn = dbapi.connect(
    address="<hostname>",
    port=3<NN>MM,
    user="<username>",
    password="<password>"
)
cursor = conn.cursor()

Execute a single statement that does not return a result set:

cursor.execute("CREATE TABLE T1 (ID INTEGER PRIMARY KEY, C2 VARCHAR(255))")
cursor.close()

Use question mark parameter binding to insert values into the T1 table created above. The parameter values are supplied as a Python sequence and can be literal values or variable names. This example uses literal values:

sql = 'INSERT INTO T1 (ID, C2) VALUES (?, ?)'
cursor = conn.cursor()
cursor.execute(sql, (1, 'hello'))
# returns True
cursor.execute(sql, (2, 'hello again'))
# returns True
cursor.close()

Use named parameter binding to insert values into the T1 table. The values are supplied as a Python dictionary, and this example uses variable names.

sql = 'INSERT INTO T1 (ID, C2) VALUES (:id, :c2)'
cursor = conn.cursor()
id = 3
c2 = "goodbye"
cursor.execute(sql, {"id": id, "c2": c2})
# returns True
cursor.close()

Loop over the rows of the result set.

sql = 'SELECT * FROM T1'
cursor = conn.cursor()
cursor.execute(sql)
for row in cursor:
    print(row)

Help

See the SAP HANA Client Interface Programming Reference for details about developing with the SAP HANA Python Client.

License

The HANA Python Client is provided via the SAP Developer License Agreement.

By using this software, you agree that the following text is incorporated into the terms of the Developer Agreement:

If you are an existing SAP customer for On Premise software, your use of this current software is also covered by the terms of your software license agreement with SAP, including the Use Rights, the current version of which can be found at: https://www.sap.com/about/agreements/product-use-and-support-terms.html?tag=agreements:product-use-support-terms/on-premise-software/software-use-rights

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for hdbcli, version 2.4.162
Filename, size File type Python version Upload date Hashes
Filename, size hdbcli-2.4.162-cp27-cp27m-macosx_10_6_x86_64.whl (5.3 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp27-cp27m-manylinux1_x86_64.whl (22.4 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp27-cp27mu-macosx_10_6_x86_64.whl (5.3 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp27-cp27mu-manylinux1_x86_64.whl (22.4 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp27-cp27m-win_amd64.whl (3.3 MB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp34-abi3-macosx_10_6_x86_64.whl (5.3 MB) File type Wheel Python version cp34 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp34-abi3-manylinux1_x86_64.whl (22.4 MB) File type Wheel Python version cp34 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp34-cp34m-win_amd64.whl (3.3 MB) File type Wheel Python version cp34 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp35-cp35m-win_amd64.whl (3.3 MB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp36-cp36m-win_amd64.whl (3.3 MB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size hdbcli-2.4.162-cp37-cp37m-win_amd64.whl (3.3 MB) File type Wheel Python version cp37 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page