hana-ml
raw JSON → 2.28.26042901 verified Fri May 01 auth: no python
Python Machine Learning Client for SAP HANA. Provides APIs to access SAP HANA's machine learning capabilities via Python. Current version: 2.28.26042901, requires Python >=3.4. Release cadence: roughly quarterly.
pip install hana-ml Common errors
error ModuleNotFoundError: No module named 'hana_ml' ↓
cause Python cannot find the hana_ml package. Either not installed or installed from wrong source.
fix
Run
pip install hana-ml and verify installation with pip list | grep hana-ml. error DBTError: db error: [SAP AG][LIBODBCHDB DLL][HDBODBC] Communication error -10: cannot connect to host ↓
cause Incorrect host, port, or network issues. Firewall or wrong address.
fix
Check HANA_HOST and HANA_PORT environment variables. Ensure the HANA instance is reachable. For testing, use
telnet <host> <port>. Warnings
breaking In version 2.20, the import path changed. Previously, `from hana_ml import DataFrame` was valid; now use `from hana_ml.dataframe import DataFrame`. Old code will break. ↓
fix Update imports to `from hana_ml.dataframe import DataFrame, ConnectionContext`.
gotcha The `hana_ml` package name is `hana-ml` on PyPI. Installing `pip install hana-ml` installs the package importable as `hana_ml`. Do not confuse with other similarly named packages. ↓
fix Use `pip install hana-ml`, then import as `hana_ml`.
deprecated The `apply` method on DataFrames for user-defined functions is deprecated in favor of `map` or vectorized UDFs. ↓
fix Use `map` or register vectorized Python UDFs via `create_udf`.
Imports
- ConnectionContext
from hana_ml.dataframe import ConnectionContext - create_dataframe_from_pandas
from hana_ml.dataframe import create_dataframe_from_pandas
Quickstart
from hana_ml.dataframe import ConnectionContext
import os
# Connect to HANA (use environment variables for credentials)
cc = ConnectionContext(
address=os.environ.get('HANA_HOST', 'localhost'),
port=int(os.environ.get('HANA_PORT', 30015)),
user=os.environ.get('HANA_USER', 'USER1'),
password=os.environ.get('HANA_PASSWORD', 'Password123')
)
print(cc.connection.isconnected())
# Create a HANA DataFrame from a SQL query
hdf = cc.sql('SELECT * FROM DUMMY')
print(hdf.head())