Runs a SQL command on SAP HANA Cloud using OAuth single sign on and returns a pandas or polars dataframe
Project description
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hana_cloud_interface-0.3.3.tar.gz.
File metadata
- Download URL: hana_cloud_interface-0.3.3.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e5364c8e956f5fec547828859ed9c893b4151c7c9844d31c699245d7f1a81e5
|
|
| MD5 |
61405b80fff1cdfa0dbdd54527bc2c31
|
|
| BLAKE2b-256 |
225b17593d628c04ea4d8de091a4adcdfa590ef6e48207d95281189c8d392890
|
File details
Details for the file hana_cloud_interface-0.3.3-py3-none-any.whl.
File metadata
- Download URL: hana_cloud_interface-0.3.3-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e08f37dbcb90c484b2f77f7a4702270084ea8b43b21d90f8a301be189881f94
|
|
| MD5 |
e55b729948dbb5377dde692fdb3c2eb3
|
|
| BLAKE2b-256 |
b61be29bb239caaad6caba0cf0f42734821b3fd92cf7625f5a5430ba27310682
|