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.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

hdbcli-2.5.105-cp38-cp38m-win_amd64.whl (3.6 MB view hashes)

Uploaded CPython 3.8m Windows x86-64

hdbcli-2.5.105-cp38-cp38-win_amd64.whl (3.6 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

hdbcli-2.5.105-cp37-cp37m-win_amd64.whl (3.6 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

hdbcli-2.5.105-cp36-cp36m-win_amd64.whl (3.6 MB view hashes)

Uploaded CPython 3.6m Windows x86-64

hdbcli-2.5.105-cp35-cp35m-win_amd64.whl (3.6 MB view hashes)

Uploaded CPython 3.5m Windows x86-64

hdbcli-2.5.105-cp34-cp34m-win_amd64.whl (3.6 MB view hashes)

Uploaded CPython 3.4m Windows x86-64

hdbcli-2.5.105-cp34-abi3-manylinux2014_ppc64le.whl (10.6 MB view hashes)

Uploaded CPython 3.4+

hdbcli-2.5.105-cp34-abi3-manylinux1_x86_64.whl (22.6 MB view hashes)

Uploaded CPython 3.4+

hdbcli-2.5.105-cp34-abi3-macosx_10_7_x86_64.whl (5.6 MB view hashes)

Uploaded CPython 3.4+ macOS 10.7+ x86-64

hdbcli-2.5.105-cp27-cp27mu-manylinux2014_ppc64le.whl (10.6 MB view hashes)

Uploaded CPython 2.7mu

hdbcli-2.5.105-cp27-cp27mu-manylinux1_x86_64.whl (22.6 MB view hashes)

Uploaded CPython 2.7mu

hdbcli-2.5.105-cp27-cp27mu-macosx_10_7_x86_64.whl (5.6 MB view hashes)

Uploaded CPython 2.7mu macOS 10.7+ x86-64

hdbcli-2.5.105-cp27-cp27m-win_amd64.whl (3.6 MB view hashes)

Uploaded CPython 2.7m Windows x86-64

hdbcli-2.5.105-cp27-cp27m-manylinux2014_ppc64le.whl (10.6 MB view hashes)

Uploaded CPython 2.7m

hdbcli-2.5.105-cp27-cp27m-manylinux1_x86_64.whl (22.6 MB view hashes)

Uploaded CPython 2.7m

hdbcli-2.5.105-cp27-cp27m-macosx_10_7_x86_64.whl (5.6 MB view hashes)

Uploaded CPython 2.7m macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page