| Name | upsolver-sdk-python JSON |
| Version |
0.1.12
JSON |
| download |
| home_page | |
| Summary | Python SDK for Upsolver |
| upload_time | 2024-03-05 13:19:24 |
| maintainer | |
| docs_url | None |
| author | Upsolver Team |
| requires_python | >=3.7,<4.0 |
| license | MIT |
| keywords |
|
| VCS |
|
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Using Upsolver with DBAPI in python
## What is Upsolver
[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.
## SQLake
[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.
## What is DB API
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.
## Getting started
### Install Upsolver SDK for Python
To use Upsolver SDK for Python you'll need Python interpreter of version greater than 3.7
```bash
# For release version:
pip install upsolver-sdk-python
# for latest development version
pip install git+https://github.com/Upsolver/upsolver-sdk-python
```
### Register Upsolver account
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.
### Create API token
After login navigate to "[Settings](https://sqlake.upsolver.com/Settings)" and then to "[API Tokens](https://sqlake.upsolver.com/Settings/api-tokens)"
You will need API token and API Url to access Upsolver programatically.

Then click "Generate" new token and save it for future use.
## Connections and cursors
Connecting to SQLake using the python SDK involves a few simple steps:
- create a `Connection`
- create a `Cursor`
- execute query
```python
# import upsolver DB API
import upsolver.dbapi as upsolver
# Configure your token and URL
token=...
api_url=...
#create connection and cursor
con = upsolver.connect(token=token,api_url=api_url)
cur = upsolver.Cursor(con)
# execute query
res = cur.execute('''
select
customer.firstname,
customer.lastname,
nettotal as total,
taxrate
from default_glue_catalog.database_8edc49.orders_raw_data
limit 5;
''')
# now we can iterate the results
for r in res:
print(r)
['John', 'Williams', '415.04', '0.12']
['Richard', 'Miller', '842.1', '0.12']
['Charles', 'Martinez', '1994.6', '0.12']
['Roy', 'Hughes', '0.0', '0.12']
['Teresa', 'Reed', '1080.72', '0.12']
```
We can use libraries to print the pretty-print the results:
```python
from beautifultable import BeautifulTable
res = cur.execute('''
select
customer.firstname,
customer.lastname,
nettotal as total,
taxrate
from default_glue_catalog.database_8edc49.orders_raw_data
limit 5;
''')
table = BeautifulTable()
table.column_headers = [c[0] for c in cur.description]
for r in res:
table.append_row(r)
print(table)
+-----------+----------+---------+---------+
| firstname | lastname | total | taxrate |
+-----------+----------+---------+---------+
| Samantha | Green | 607.53 | 0.12 |
+-----------+----------+---------+---------+
| Virginia | Evans | 270.02 | 0.12 |
+-----------+----------+---------+---------+
| Abigail | Watson | 1194.39 | 0.12 |
+-----------+----------+---------+---------+
| Ann | Bailey | 1655.7 | 0.12 |
+-----------+----------+---------+---------+
| Kelly | Edwards | 1368.78 | 0.12 |
+-----------+----------+---------+---------+
```
Note: The examples above use the sample data provided by the template "S3 to Athena" in SQLake
## We can use pandas too
`pandas` is very popular library for data maipulations.
It's possible to rewrite the above example with pandas
```python
import pandas as pd
df = pd.read_sql(query,con=con)
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 firstname 5 non-null object
1 lastname 5 non-null object
2 total 5 non-null object
3 taxrate 5 non-null object
dtypes: object(4)
```

## Upsolver SQL
See Upsolver's [SQL Command Reference](https://docs.upsolver.com/sqlake/sql-command-reference) for the supported SQL commands and syntax.
## Further reading
[upsolver.com](https://upsolver.com)
[Documentation](https://docs.upsolver.com/sqlake/sql-command-reference) of Upsolver SQL
[upsolver-sdk-python](https://github.com/Upsolver/upsolver-sdk-python) - GitHub repository with upsolver SDK for Python language
[SQLake workbench](https://sqlake.upsolver.com/) main page
[Python examples from this README](https://github.com/Upsolver/upsolver-sdk-python/blob/develop/doc/dbapi-ex.py)
[Upsolver Comunity Slack](https://join.slack.com/t/upsolvercommunity/shared_invite/zt-1zo1dbyys-hj28WfaZvMh4Z4Id3OkkhA)
Raw data
{
"_id": null,
"home_page": "",
"name": "upsolver-sdk-python",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Upsolver Team",
"author_email": "info@upsolver.com",
"download_url": "https://files.pythonhosted.org/packages/e2/e4/3ffad780fdda73aa4e6560d0d7043876f0299a3b69fa001856b14c004028/upsolver_sdk_python-0.1.12.tar.gz",
"platform": null,
"description": "# Using Upsolver with DBAPI in python\n\n## What is Upsolver\n\n[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.\n\n## SQLake\n\n[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.\n\n\n## What is DB API\n\nPython'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.\n\n## Getting started\n\n### Install Upsolver SDK for Python\n\nTo use Upsolver SDK for Python you'll need Python interpreter of version greater than 3.7 \n\n```bash\n# For release version:\npip install upsolver-sdk-python\n# for latest development version\npip install git+https://github.com/Upsolver/upsolver-sdk-python\n```\n\n### Register Upsolver account\n\nTo 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.\n\n### Create API token\n\nAfter login navigate to \"[Settings](https://sqlake.upsolver.com/Settings)\" and then to \"[API Tokens](https://sqlake.upsolver.com/Settings/api-tokens)\"\n\nYou will need API token and API Url to access Upsolver programatically.\n\n\n\nThen click \"Generate\" new token and save it for future use.\n\n## Connections and cursors\n\nConnecting to SQLake using the python SDK involves a few simple steps:\n\n- create a `Connection`\n- create a `Cursor`\n- execute query\n\n```python\n# import upsolver DB API\nimport upsolver.dbapi as upsolver\n\n# Configure your token and URL\ntoken=...\napi_url=...\n\n#create connection and cursor\ncon = upsolver.connect(token=token,api_url=api_url)\ncur = upsolver.Cursor(con)\n\n# execute query\nres = cur.execute('''\n select\n customer.firstname,\n customer.lastname,\n nettotal as total,\n taxrate\n from default_glue_catalog.database_8edc49.orders_raw_data\n limit 5;\n''')\n\n# now we can iterate the results\nfor r in res:\n print(r)\n\n['John', 'Williams', '415.04', '0.12']\n['Richard', 'Miller', '842.1', '0.12']\n['Charles', 'Martinez', '1994.6', '0.12']\n['Roy', 'Hughes', '0.0', '0.12']\n['Teresa', 'Reed', '1080.72', '0.12']\n```\n\nWe can use libraries to print the pretty-print the results:\n\n```python\nfrom beautifultable import BeautifulTable\n\nres = cur.execute('''\n select\n customer.firstname,\n customer.lastname,\n nettotal as total,\n taxrate\n from default_glue_catalog.database_8edc49.orders_raw_data\n limit 5;\n''')\n\ntable = BeautifulTable()\ntable.column_headers = [c[0] for c in cur.description]\nfor r in res:\n table.append_row(r)\nprint(table)\n+-----------+----------+---------+---------+\n| firstname | lastname | total | taxrate |\n+-----------+----------+---------+---------+\n| Samantha | Green | 607.53 | 0.12 |\n+-----------+----------+---------+---------+\n| Virginia | Evans | 270.02 | 0.12 |\n+-----------+----------+---------+---------+\n| Abigail | Watson | 1194.39 | 0.12 |\n+-----------+----------+---------+---------+\n| Ann | Bailey | 1655.7 | 0.12 |\n+-----------+----------+---------+---------+\n| Kelly | Edwards | 1368.78 | 0.12 |\n+-----------+----------+---------+---------+\n```\n\nNote: The examples above use the sample data provided by the template \"S3 to Athena\" in SQLake\n\n## We can use pandas too\n\n`pandas` is very popular library for data maipulations.\nIt's possible to rewrite the above example with pandas\n\n```python\nimport pandas as pd\n\ndf = pd.read_sql(query,con=con)\ndf.info()\n<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 5 entries, 0 to 4\nData columns (total 4 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 firstname 5 non-null object\n 1 lastname 5 non-null object\n 2 total 5 non-null object\n 3 taxrate 5 non-null object\ndtypes: object(4)\n```\n\n\n\n## Upsolver SQL\n\nSee Upsolver's [SQL Command Reference](https://docs.upsolver.com/sqlake/sql-command-reference) for the supported SQL commands and syntax.\n\n## Further reading\n\n[upsolver.com](https://upsolver.com)\n\n[Documentation](https://docs.upsolver.com/sqlake/sql-command-reference) of Upsolver SQL\n\n[upsolver-sdk-python](https://github.com/Upsolver/upsolver-sdk-python) - GitHub repository with upsolver SDK for Python language\n\n[SQLake workbench](https://sqlake.upsolver.com/) main page\n\n[Python examples from this README](https://github.com/Upsolver/upsolver-sdk-python/blob/develop/doc/dbapi-ex.py)\n\n[Upsolver Comunity Slack](https://join.slack.com/t/upsolvercommunity/shared_invite/zt-1zo1dbyys-hj28WfaZvMh4Z4Id3OkkhA)\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python SDK for Upsolver",
"version": "0.1.12",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7c53214408e11e3b1e3878290573641dab0d508c146519386b1166ddf4ae50fb",
"md5": "b68972ecb2194acb689469e6dbacfcda",
"sha256": "bb3f8060b446e812440238629e5ea88bd26560809a4bf8e99063cb1e91a96bcc"
},
"downloads": -1,
"filename": "upsolver_sdk_python-0.1.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b68972ecb2194acb689469e6dbacfcda",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 20713,
"upload_time": "2024-03-05T13:19:23",
"upload_time_iso_8601": "2024-03-05T13:19:23.832963Z",
"url": "https://files.pythonhosted.org/packages/7c/53/214408e11e3b1e3878290573641dab0d508c146519386b1166ddf4ae50fb/upsolver_sdk_python-0.1.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e2e43ffad780fdda73aa4e6560d0d7043876f0299a3b69fa001856b14c004028",
"md5": "a6d5176a3c597d327dc7c00a941c5ec0",
"sha256": "0c630d6864bb73dc93542d12f87eb4212a09d45225d53ed07ae6e29bf8731400"
},
"downloads": -1,
"filename": "upsolver_sdk_python-0.1.12.tar.gz",
"has_sig": false,
"md5_digest": "a6d5176a3c597d327dc7c00a941c5ec0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 16827,
"upload_time": "2024-03-05T13:19:24",
"upload_time_iso_8601": "2024-03-05T13:19:24.969569Z",
"url": "https://files.pythonhosted.org/packages/e2/e4/3ffad780fdda73aa4e6560d0d7043876f0299a3b69fa001856b14c004028/upsolver_sdk_python-0.1.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-05 13:19:24",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "upsolver-sdk-python"
}