hana-cloud-interface 0.1.4__tar.gz → 0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of hana-cloud-interface might be problematic. Click here for more details.
- hana_cloud_interface-0.1.6/PKG-INFO +59 -0
- hana_cloud_interface-0.1.6/README.md +46 -0
- {hana_cloud_interface-0.1.4 → hana_cloud_interface-0.1.6}/pyproject.toml +1 -1
- hana_cloud_interface-0.1.6/src/hana_cloud_interface/__init__.py +1 -0
- {hana_cloud_interface-0.1.4 → hana_cloud_interface-0.1.6}/src/hana_cloud_interface/main.py +27 -9
- hana_cloud_interface-0.1.4/PKG-INFO +0 -13
- hana_cloud_interface-0.1.4/README.md +0 -0
- hana_cloud_interface-0.1.4/src/hana_cloud_interface/__init__.py +0 -1
- {hana_cloud_interface-0.1.4 → hana_cloud_interface-0.1.6}/src/hana_cloud_interface/py.typed +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: hana-cloud-interface
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: Runs a SQL command on SAP HANA Cloud using OAuth single sign on and returns a pandas or polars dataframe
|
|
5
|
+
Author: charlotte corpe
|
|
6
|
+
Author-email: charlotte corpe <charlotte.corpe@powerco.co.nz>
|
|
7
|
+
Requires-Dist: keyring
|
|
8
|
+
Requires-Dist: hdbcli
|
|
9
|
+
Requires-Dist: polars
|
|
10
|
+
Requires-Dist: pandas
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Usage of the `hana_cloud_interface` package
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## example
|
|
20
|
+
the main function is very simple It takes a SQL command as a string and returns the data
|
|
21
|
+
```python
|
|
22
|
+
import hana_cloud_interface as hci
|
|
23
|
+
|
|
24
|
+
sql_command = """
|
|
25
|
+
SELECT top 10
|
|
26
|
+
"data1"
|
|
27
|
+
"data2"
|
|
28
|
+
FROM "table1"
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
data = hci.hana_sql(sql_command)
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## initialising settings
|
|
36
|
+
Before using the package, you need to initialize the settings by specifying the configuration file location, browser override (if needed), and the default data frame type for SQL query results.
|
|
37
|
+
|
|
38
|
+
config_file : Path to the configuration file (JSON format) containing OAuth credentials and other settings.
|
|
39
|
+
|
|
40
|
+
Browser_override : Optional parameter to specify a browser for OAuth authentication. If left empty, the default browser will be used. this needs to be the path to the executable for the browser
|
|
41
|
+
|
|
42
|
+
data_frame_type : Default data frame type for SQL query results. Options are 'pandas' or 'polars'. Default is 'pandas'.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
hci.initialize_settings(config_file = 'location of configuration file', Browser_override = '', data_frame_type = 'pandas')
|
|
46
|
+
```
|
|
47
|
+
the configuration file is a .json file
|
|
48
|
+
```python
|
|
49
|
+
{
|
|
50
|
+
"CLIENT_ID": "",
|
|
51
|
+
"CLIENT_SECRET": "",
|
|
52
|
+
"AUTH_URL": "",
|
|
53
|
+
"TOKEN_URL": "",
|
|
54
|
+
"protected_url": "",
|
|
55
|
+
"REDIRECT_URI": "",
|
|
56
|
+
"SCOPE": "",
|
|
57
|
+
"HC_prod_URL": ""
|
|
58
|
+
}
|
|
59
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Usage of the `hana_cloud_interface` package
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## example
|
|
7
|
+
the main function is very simple It takes a SQL command as a string and returns the data
|
|
8
|
+
```python
|
|
9
|
+
import hana_cloud_interface as hci
|
|
10
|
+
|
|
11
|
+
sql_command = """
|
|
12
|
+
SELECT top 10
|
|
13
|
+
"data1"
|
|
14
|
+
"data2"
|
|
15
|
+
FROM "table1"
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
data = hci.hana_sql(sql_command)
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## initialising settings
|
|
23
|
+
Before using the package, you need to initialize the settings by specifying the configuration file location, browser override (if needed), and the default data frame type for SQL query results.
|
|
24
|
+
|
|
25
|
+
config_file : Path to the configuration file (JSON format) containing OAuth credentials and other settings.
|
|
26
|
+
|
|
27
|
+
Browser_override : Optional parameter to specify a browser for OAuth authentication. If left empty, the default browser will be used. this needs to be the path to the executable for the browser
|
|
28
|
+
|
|
29
|
+
data_frame_type : Default data frame type for SQL query results. Options are 'pandas' or 'polars'. Default is 'pandas'.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
hci.initialize_settings(config_file = 'location of configuration file', Browser_override = '', data_frame_type = 'pandas')
|
|
33
|
+
```
|
|
34
|
+
the configuration file is a .json file
|
|
35
|
+
```python
|
|
36
|
+
{
|
|
37
|
+
"CLIENT_ID": "",
|
|
38
|
+
"CLIENT_SECRET": "",
|
|
39
|
+
"AUTH_URL": "",
|
|
40
|
+
"TOKEN_URL": "",
|
|
41
|
+
"protected_url": "",
|
|
42
|
+
"REDIRECT_URI": "",
|
|
43
|
+
"SCOPE": "",
|
|
44
|
+
"HC_prod_URL": ""
|
|
45
|
+
}
|
|
46
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .main import hana_sql, initialize_settings
|
|
@@ -13,11 +13,29 @@ import polars as pl
|
|
|
13
13
|
import pandas as pd
|
|
14
14
|
import os
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
config_file_g = ''
|
|
17
|
+
Browser_override_g = ''
|
|
18
|
+
data_frame_type_g = 'pandas' # Default data frame type for hana_sql function
|
|
19
19
|
debug = False
|
|
20
20
|
|
|
21
|
+
def initialize_settings(config_file = '', Browser_override = '', data_frame_type = 'pandas'):
|
|
22
|
+
"""
|
|
23
|
+
Initializes global settings for the Hana Cloud interface.
|
|
24
|
+
|
|
25
|
+
Parameters:
|
|
26
|
+
config_file (str): Path to the configuration file.
|
|
27
|
+
Browser_override (str): Optional browser override for OAuth authentication.
|
|
28
|
+
data_frame_type (str): Default data frame type for SQL query results ('pandas' or 'polars').
|
|
29
|
+
|
|
30
|
+
Sets global variables for configuration file path, browser override, and data frame type.
|
|
31
|
+
"""
|
|
32
|
+
global config_file_g, Browser_override_g, data_frame_type_g
|
|
33
|
+
config_file_g = config_file
|
|
34
|
+
Browser_override_g = Browser_override
|
|
35
|
+
data_frame_type_g = data_frame_type
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
21
39
|
def test_connection(oauth_config):
|
|
22
40
|
oauth_Token = keyring.get_password('SAP_hana_sso', 'oauth_Token')
|
|
23
41
|
|
|
@@ -159,8 +177,8 @@ def get_token(i=0):
|
|
|
159
177
|
authorization_url = f"{oauth_config['AUTH_URL']}?{urllib.parse.urlencode(params)}"
|
|
160
178
|
|
|
161
179
|
# Open web browser and go to oauth url
|
|
162
|
-
if
|
|
163
|
-
webbrowser.get(
|
|
180
|
+
if Browser_overrid_ge != '':
|
|
181
|
+
webbrowser.get(Browser_override_g).open(authorization_url,new=1)
|
|
164
182
|
else:
|
|
165
183
|
webbrowser.open(authorization_url,new=1)
|
|
166
184
|
|
|
@@ -188,9 +206,9 @@ def config_reader():
|
|
|
188
206
|
# reads config data from keychain
|
|
189
207
|
config_data = keyring.get_password('SAP_hana_sso', 'config_data')
|
|
190
208
|
if not config_data: # If there is no existing config data saved to the credentials manager read from file and save it
|
|
191
|
-
if not os.path.exists(
|
|
192
|
-
raise FileNotFoundError(f"Config file not found: {
|
|
193
|
-
with open(
|
|
209
|
+
if not os.path.exists(config_file_g):
|
|
210
|
+
raise FileNotFoundError(f"Config file not found: {config_file_g}")
|
|
211
|
+
with open(config_file_g) as file:
|
|
194
212
|
config_data = json.load(file)
|
|
195
213
|
keyring.set_password('SAP_hana_sso', 'config_data', json.dumps(config_data))
|
|
196
214
|
return config_data
|
|
@@ -200,7 +218,7 @@ def config_reader():
|
|
|
200
218
|
|
|
201
219
|
|
|
202
220
|
|
|
203
|
-
def hana_sql(sql_command='test',DF_type =
|
|
221
|
+
def hana_sql(sql_command='test',DF_type = data_frame_type_g):
|
|
204
222
|
""" handles single sign on then runs a SQL command
|
|
205
223
|
|
|
206
224
|
Parameters:
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: hana-cloud-interface
|
|
3
|
-
Version: 0.1.4
|
|
4
|
-
Summary: Runs a SQL command on SAP HANA Cloud using OAuth single sign on and returns a pandas or polars dataframe
|
|
5
|
-
Author: charlotte corpe
|
|
6
|
-
Author-email: charlotte corpe <charlotte.corpe@powerco.co.nz>
|
|
7
|
-
Requires-Dist: keyring
|
|
8
|
-
Requires-Dist: hdbcli
|
|
9
|
-
Requires-Dist: polars
|
|
10
|
-
Requires-Dist: pandas
|
|
11
|
-
Requires-Python: >=3.12
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .main import hana_sql, config_file, data_frame_type, Browser_override
|
|
File without changes
|