PyHDB - SAP HANA Database Client
raw JSON → 0.3.4 verified Fri May 01 auth: no python maintenance
PyHDB is a pure Python client library for connecting to SAP HANA databases. It implements the SAP HANA database protocol (based on Python DB API 2.0) and supports features like LOBs, geometry types, procedures with resultsets, and SELECT FOR UPDATE. The current version is 0.3.4, released in December 2016 with bug fixes. The project is in maintenance mode with no recent releases.
pip install pyhdb Common errors
error ImportError: No module named pyhdb ↓
cause PyHDB is not installed or installed in wrong environment.
fix
Run 'pip install pyhdb'. If in a virtual environment, ensure it is activated.
error pyhdb.exceptions.OperationalError: Connection refused ↓
cause The HANA host or port is incorrect, or the HANA instance is not reachable.
fix
Check host and port values. Use 'telnet <host> <port>' to verify connectivity. Ensure the HANA instance is running and listening.
error AttributeError: module 'pyhdb' has no attribute 'connect' ↓
cause The 'connect' function is deprecated or not available; use Connection class with connect() method.
fix
Use 'from pyhdb import Connection' then 'conn = Connection(...).connect()'.
Warnings
deprecated PyHDB is effectively in maintenance mode. The last release was in 2016. Consider using the official SAP HANA Python driver 'hdbcli' instead. SAP has provided hdbcli as the recommended client. ↓
fix Switch to 'pip install hdbcli' and use 'from hdbcli import dbapi'.
gotcha PyHDB uses Python 2/3 compatibility via 'six'. On Python 3, ensure you have a recent enough version to avoid subtle encoding issues with strings. ↓
fix Install or update 'six' to the latest version.
gotcha The connection parameters 'host' and 'port' are required but often misconfigured. The default port for HANA (3xx10) is 39013, not the common 30015. Using wrong port will raise a timeout error. ↓
fix Verify the correct HANA port with your administrator. Common ports: 30015 (MDC), 39013 (tenant DB).
breaking In v0.3.2, the 'connect' function was renamed to 'connection'? Actually, check the README: the correct class is 'Connection' from 'pyhdb'. But there was a change in connection method signature. Ensure you use 'connect()' method on the Connection object, not 'open()'. ↓
fix Use connection.connect() after creating the Connection object.
Imports
- Connection wrong
from sap import ...correctfrom pyhdb import Connection
Quickstart
from pyhdb import Connection
connection = Connection(
host=os.environ.get('HANA_HOST', 'localhost'),
port=os.environ.get('HANA_PORT', 39013),
user=os.environ.get('HANA_USER', 'user'),
password=os.environ.get('HANA_PASSWORD', 'pass')
)
connection.connect()
cursor = connection.cursor()
cursor.execute("SELECT 'Hello, World!' FROM DUMMY")
print(cursor.fetchone())
connection.close()