SQL for Google Sheets
Project description
sheet-sql
sheet-sql allows for writing SQL-style queries to query data from Google Sheets. It makes use of Google's Table Query (tq) Language. See here for more details.
>>> from sheetsql import connect
>>> gs = connect("service_account")
>>> gs.spreadsheets
[<Spreadsheet 'Test' id:1z2917zfaUqeE9-fMn-XAUvDwzQ8Q_2rEXHRst5KZC3I>, <Spreadsheet 'my new spreadsheet' id:1I4pfBHYoY_ajW13Tn8t2-AyqmWK1HzcJPccyRUefdyw>]
>>> spreadsheet = gs['1z2917zfaUqeE9-fMn-XAUvDwzQ8Q_2rEXHRst5KZC3I']
>>> spreadsheet
<Spreadsheet 'Test' id:1z2917zfaUqeE9-fMn-XAUvDwzQ8Q_2rEXHRst5KZC3I>
>>> spreadsheet.worksheets
['Sheet1', 'Sheet2']
>>> worksheet = spreadsheet['Sheet1']
>>> worksheet
<Worksheet 'Sheet1' id:0>
>>> worksheet.columns
['test', 'test2', 'test3']
>>> query = worksheet.query("SELECT *")
<generator object Worksheet._result_handler.<locals>.<genexpr> at 0x7fe86c3c2840>
>>> for row in query:
... print(row)
...
{'test': 1.0, 'test2': 6.0, 'test3': 11.0}
{'test': 2.0, 'test2': 7.0, 'test3': 12.0}
{'test': 3.0, 'test2': 8.0, 'test3': 13.0}
{'test': 4.0, 'test2': 9.0, 'test3': 14.0}
{'test': 5.0, 'test2': 10.0, 'test3': 15.0}
>>> worksheet.default_row_type
<class 'dict'>
>>> worksheet.default_row_type = list
>>> worksheet.default_row_type
<class 'list'>
>>> query = worksheet.query("SELECT *")
>>> for row in query:
... print(row)
...
[1.0, 6.0, 11.0]
[2.0, 7.0, 12.0]
[3.0, 8.0, 13.0]
[4.0, 9.0, 14.0]
[5.0, 10.0, 15.0]
To install, run
pip install sheet-sql
Alternatively, install with poetry
poetry add sheet-sql
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
sheet-sql-0.1.0.tar.gz
(6.6 kB
view hashes)
Built Distribution
Close
Hashes for sheet_sql-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5e8e4e04f5cd7b314d4bdfcc09d35cee976dc6d8793332d10c71ebbf3f0641f |
|
MD5 | 6b47c0df88f86891d7ea76402847a584 |
|
BLAKE2b-256 | 2ea37828582cae461aed8936599034d99948cadd135a27c0f8e709de2c3bc100 |