Usage of the hana_cloud_interface package
This package provides a simple interface to connect to SAP HANA Cloud databases and execute SQL queries. Below are some examples of how to use the package.
initialising class
when initialising the class it has two optional args.
-
config_file : Path to the configuration file (JSON format) containing OAuth credentials and other settings. the config file only needs to be added on the first time running the class on a computer.
-
data_frame_type : Default data frame type for SQL query results. Options are 'pandas' or 'polars'. Default is 'pandas'. if the data type is not added here it will need to be added for every time you run hana_sql function
Hana_cloud_interface(config_file = 'location of configuration file', df = 'pandas')
hana_sql() function
Execute a SQL command on the HANA Cloud database and return the result as a DataFrame.
Args: sql_command (str, optional): The SQL command to execute. Defaults to 'validate', which only checks the connection. DF_type_local_override (str, optional): DataFrame type for this query ('pandas' or 'polars'). Overrides the global setting if provided.
Returns: str: If sql_command is 'validate', returns a validation message. pandas.DataFrame or polars.DataFrame: The query result as a DataFrame, depending on the specified or default DataFrame type.
Raises: ValueError: If the DataFrame type is not specified or is invalid.
hana_upload() function
Upload a DataFrame to the HANA Cloud database.
Args: data (pandas.DataFrame or polars.DataFrame): The data to upload. If a polars DataFrame is provided, it will be converted to pandas. data_name (str): The name of the table to create or replace in HANA Cloud. SCHEMA (str): The schema in which to create the table.
Returns: bool: True if the upload is successful.
Raises: Exception: If the upload fails due to connection or data issues.
configuration file
the configuration file is a .json file
{
"CLIENT_ID": "",
"CLIENT_SECRET": "",
"AUTH_URL": "",
"TOKEN_URL": "",
"protected_url": "",
"REDIRECT_URI": "",
"SCOPE": "",
"HC_prod_URL": ""
}
example
the main function is very simple It takes a SQL command as a string and returns the data
import hana_cloud_interface
# initialise class
hci = Hana_cloud_interface(df='polars')
sql_command = """
SELECT top 10
"data1"
"data2"
FROM "table1"
"""
data = hci.hana_sql(sql_command)
Metadata
Release files for hana-cloud-interface 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hana_cloud_interface-0.3.5.tar.gz | 8.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hana_cloud_interface-0.3.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.9 kB
Release files / hana_cloud_interface-0.3.5.tar.gz
| Download URL | hana_cloud_interface-0.3.5.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f538b9246ab471f1a7066e7be98a90712023c8100065a9bab7853e1669742b5a
|
|
BLAKE2b-256 checksum How to use checksums |
c1345dd204c9a2ccc496e930ca980e873c509230138298e3e29520798b737d23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / hana_cloud_interface-0.3.5-py3-none-any.whl
| Download URL | hana_cloud_interface-0.3.5-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ae1c5b925c16f5dca166f02af02312ccbe20dca83d79e2da8f19d1b1691e38f0
|
|
BLAKE2b-256 checksum How to use checksums |
46f5d5ab169cae9d0c36bde8c56050e58c0dff82bcfc1a5028e462876439de05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|