Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.

Commit f779e72

Browse files
authored
Merge branch 'develop' into code_cleanup
2 parents 0569091 + fe5863b commit f779e72

File tree

15 files changed

+271
-7
lines changed

15 files changed

+271
-7
lines changed

.github/workflows/release.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [ published ]
6+
branches: [ develop ]
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- name: Determine Version
15+
id: release-version
16+
run: |
17+
echo "::set-output name=full::${{ github.ref_name }}"
18+
SIMPLE=$(echo ${{ github.ref_name }} | sed -e s/^v//)
19+
echo "::set-output name=simple::$SIMPLE"
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: ">=3.7"
25+
26+
- name: Install dependencies
27+
run: |
28+
curl -sSL https://install.python-poetry.org | python3 -
29+
poetry install
30+
31+
- name: Build package
32+
run: poetry build
33+
34+
- name: Upload Release Asset (source distribution)
35+
uses: actions/upload-release-asset@v1
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
with:
39+
upload_url: ${{ github.event.release.upload_url }}
40+
asset_path: ./dist/upsolver_sdk_python-${{ steps.release-version.outputs.simple }}.tar.gz
41+
asset_name: upsolver_sdk_python.tar.gz
42+
asset_content_type: application/tar+gz
43+
44+
- name: Publish distribution 📦 to Test PyPI
45+
uses: pypa/gh-action-pypi-publish@release/v1
46+
with:
47+
password: ${{ secrets.TEST_PYPI_TOKEN_NESTLOGIC }}
48+
repository_url: https://test.pypi.org/legacy/
49+
50+
- name: Upload Release Asset (built distribution)
51+
uses: actions/upload-release-asset@v1
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
with:
55+
upload_url: ${{ github.event.release.upload_url }}
56+
asset_path: ./dist/upsolver_sdk_python-${{ steps.release-version.outputs.simple }}-py3-none-any.whl
57+
asset_name: upsolver_sdk_python-${{ steps.release-version.outputs.simple }}-py3-none-any.whl
58+
asset_content_type: application/whl

README.md

Lines changed: 159 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,160 @@
1-
# upsolver-sdk-python
1+
# Using Upsolver with DBAPI in python
22

3+
## What is Upsolver
4+
5+
[Upsolver](https://upsolver.com) enables you to use familiar SQL syntax to quickly build and deploy data pipelines, powered by a stream processing engine designed for cloud data lakes.
6+
7+
## SQLake
8+
9+
[SQLake](https://docs.upsolver.com/sqlake) is Upsolvers new UI and SQL console allowing to execute commands and monitor pipelines in the UI. It also includes freee trial and access to variety of examples and tutorials.
10+
11+
12+
## What is DB API
13+
14+
Python's DB API 2.0 is defined in [pep-249](https://peps.python.org/pep-0249/). It defines an abstract API for connecting and working with databases in Python. Many python libraries support DB API v2.0 natively, for example `pandas`, `SQLAlchemy`, and more.
15+
16+
## Getting started
17+
18+
### Install Upsolver SDK for Python
19+
20+
To use Upsolver SDK for Python you'll need Python interpreter of version greater than 3.7
21+
22+
```bash
23+
# For release version:
24+
pip install upsolver-sdk-python
25+
# for latest development version
26+
pip install git+https://github.com/Upsolver/upsolver-sdk-python
27+
```
28+
29+
### Register Upsolver account
30+
31+
To register just navigate to [SQL Lake Sign Up form](https://sqlake.upsolver.com/signup). You'll have access to SQL workbench with examples and tutorials after completing the registration.
32+
33+
### Create API token
34+
35+
After login navigate to "[Settings](https://sqlake.upsolver.com/Settings)" and then to "[API Tokens](https://sqlake.upsolver.com/Settings/api-tokens)"
36+
37+
You will need API token and API Url to access Upsolver programatically.
38+
39+
![API Tokens screen](https://github.com/Upsolver/upsolver-sdk-python/raw/build_package/doc/img/APITokens-m.png)
40+
41+
Then click "Generate" new token and save it for future use.
42+
43+
## Connections and cursors
44+
45+
Connecting to SQLake using the python SDK involves a few simple steps:
46+
47+
- create a `Connection`
48+
- create a `Cursor`
49+
- execute query
50+
51+
```python
52+
# import upsolver DB API
53+
import upsolver.dbapi as upsolver
54+
55+
# Configure your token and URL
56+
token=...
57+
api_url=...
58+
59+
#create connection and cursor
60+
con = upsolver.connect(token=token,api_url=api_url)
61+
cur = upsolver.Cursor(con)
62+
63+
# execute query
64+
res = cur.execute('''
65+
select
66+
customer.firstname,
67+
customer.lastname,
68+
nettotal as total,
69+
taxrate
70+
from default_glue_catalog.database_8edc49.orders_raw_data
71+
limit 5;
72+
''')
73+
74+
# now we can iterate the results
75+
for r in res:
76+
print(r)
77+
78+
['John', 'Williams', '415.04', '0.12']
79+
['Richard', 'Miller', '842.1', '0.12']
80+
['Charles', 'Martinez', '1994.6', '0.12']
81+
['Roy', 'Hughes', '0.0', '0.12']
82+
['Teresa', 'Reed', '1080.72', '0.12']
83+
```
84+
85+
We can use libraries to print the pretty-print the results:
86+
87+
```python
88+
from beautifultable import BeautifulTable
89+
90+
res = cur.execute('''
91+
select
92+
customer.firstname,
93+
customer.lastname,
94+
nettotal as total,
95+
taxrate
96+
from default_glue_catalog.database_8edc49.orders_raw_data
97+
limit 5;
98+
''')
99+
100+
table = BeautifulTable()
101+
table.column_headers = [c[0] for c in cur.description]
102+
for r in res:
103+
table.append_row(r)
104+
print(table)
105+
+-----------+----------+---------+---------+
106+
| firstname | lastname | total | taxrate |
107+
+-----------+----------+---------+---------+
108+
| Samantha | Green | 607.53 | 0.12 |
109+
+-----------+----------+---------+---------+
110+
| Virginia | Evans | 270.02 | 0.12 |
111+
+-----------+----------+---------+---------+
112+
| Abigail | Watson | 1194.39 | 0.12 |
113+
+-----------+----------+---------+---------+
114+
| Ann | Bailey | 1655.7 | 0.12 |
115+
+-----------+----------+---------+---------+
116+
| Kelly | Edwards | 1368.78 | 0.12 |
117+
+-----------+----------+---------+---------+
118+
```
119+
120+
Note: The examples above use the sample data provided by the template "S3 to Athena" in SQLake
121+
122+
## We can use pandas too
123+
124+
`pandas` is very popular library for data maipulations.
125+
It's possible to rewrite the above example with pandas
126+
127+
```python
128+
import pandas as pd
129+
130+
df = pd.read_sql(query,con=con)
131+
df.info()
132+
<class 'pandas.core.frame.DataFrame'>
133+
RangeIndex: 5 entries, 0 to 4
134+
Data columns (total 4 columns):
135+
# Column Non-Null Count Dtype
136+
--- ------ -------------- -----
137+
0 firstname 5 non-null object
138+
1 lastname 5 non-null object
139+
2 total 5 non-null object
140+
3 taxrate 5 non-null object
141+
dtypes: object(4)
142+
```
143+
144+
![`df.head()`](https://github.com/Upsolver/upsolver-sdk-python/raw/build_package/doc/img/df.head-m.jpeg)
145+
146+
## Upsolver SQL
147+
148+
See Upsolver's [SQL Command Reference](https://docs.upsolver.com/sqlake/sql-command-reference) for the supported SQL commands and syntax.
149+
150+
## Further reading
151+
152+
[upsolver.com](https://upsolver.com)
153+
154+
[Documentation](https://docs.upsolver.com/sqlake/sql-command-reference) of Upsolver SQL
155+
156+
[upsolver-sdk-python](https://github.com/Upsolver/upsolver-sdk-python) - GitHub repository with upsolver SDK for Python language
157+
158+
[SQLake workbench](https://sqlake.upsolver.com/) main page
159+
160+
[Python examples from this README](doc/dbapi-ex.py)

doc/dbapi-ex.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
3+
#%%
4+
# pip install upsolver-sdk-python
5+
# pip install pandas
6+
# pip install git+https://github.com/Upsolver/upsolver-sdk-python
7+
# %%
8+
import upsolver.dbapi as upsolver
9+
# %%
10+
con = upsolver.connect(token='..',api_url='..')
11+
cur = upsolver.Cursor(con)
12+
# %%
13+
query = '''
14+
select
15+
customer.firstname,
16+
customer.lastname,
17+
nettotal as total,
18+
taxrate
19+
from default_glue_catalog.database_8edc49.orders_raw_data
20+
limit 5;
21+
'''
22+
res = cur.execute(query)
23+
# %%
24+
for r in res:
25+
print(r)
26+
# %%
27+
from beautifultable import BeautifulTable
28+
# %%
29+
print([c[0] for c in cur.description])
30+
#%%
31+
table = BeautifulTable()
32+
table.column_headers = [c[0] for c in cur.description]
33+
for r in res:
34+
table.append_row(r)
35+
print(table)
36+
# %%
37+
import pandas as pd
38+
39+
df = pd.read_sql(query,con=con)
40+
# %%
41+
df.info()
42+
# %%
43+
df.head()
44+
# %%

doc/img/API Token-s.jpeg

6.84 KB
Loading

doc/img/API Token.png

24 KB
Loading

doc/img/API Tokens.png

254 KB
Loading

doc/img/APITokens-m.jpeg

32.5 KB
Loading

doc/img/APITokens-m.png

757 KB
Loading

doc/img/New Token.png

58.7 KB
Loading

doc/img/SQLWorkbench-M.jpeg

50.5 KB
Loading

0 commit comments

Comments
 (0)