Skip to main content

SQL for Google Sheets

Project description

sheet-sql

Build Codecov PyPI Read the Docs

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


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 details)

Uploaded Source

Built Distribution

sheet_sql-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file sheet-sql-0.1.0.tar.gz.

File metadata

  • Download URL: sheet-sql-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.3 Linux/5.3.0-1028-azure

File hashes

Hashes for sheet-sql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2efcb5d21c45b1ebc34ddd73293ef65210c753be1f672725ba3d4828eced2e79
MD5 9a1888dab0e4dca976d21d135742d969
BLAKE2b-256 e732bc6298ab17cab134576b9b2e77ff9e81ab780da79badb7ac47582a2aa972

See more details on using hashes here.

File details

Details for the file sheet_sql-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sheet_sql-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.3 Linux/5.3.0-1028-azure

File hashes

Hashes for sheet_sql-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5e8e4e04f5cd7b314d4bdfcc09d35cee976dc6d8793332d10c71ebbf3f0641f
MD5 6b47c0df88f86891d7ea76402847a584
BLAKE2b-256 2ea37828582cae461aed8936599034d99948cadd135a27c0f8e709de2c3bc100

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page