GSheetDB
A simple way to use Google Sheet as your Data Base with own authentication system.
No google workspace project is needed.
Install
pip install gsheetdb
Setup
- Create a google sheet
- Add as many sheets (tables) as you want
- First line is table header, first column must be
id - Table relationship: set a column header with the name of a table, its content is the id (or ids) of the other table
- Go to "Extensions > App Script"
- Copy the content of the file
gsheet.jsto the current file. - Create a new deploy: "Deploy > New deployment"
- Select type: "Web app"
- Description: Anything you wanted
- Execute as: "Me (your_email@gmail.com)"
- Who has access: "Anyone"
- Copy Deployment ID
Usage
from gsheetdb import Sheet
const sheet = Sheet({ 'deploymentId': '123456789abcdef' })
Get Tables Schemas
sheet.get()
Get Table Item
Return all items
const data = sheet.get('Sheet1')
Add Item
Ids are generated automaticaly
sheet.set('Sheet1', [
{'col1': 'val1', 'col2': 2, 'col3': datetime.datetime()},
{'col1': 'val2', 'col2': 3, 'col3': datetime.datetime()},
])
Modify Item
Same API as set but with id. If id doesn't exist, it fails.
sheet.set('Sheet1', [
{id: 1234, 'col1': 'val2'}
])
Delete Item
Remove by item ids
sheet.rm('Sheet1', [1234])
New Table
sheet.new('MyNewSheetName', ['field1', 'field2', 'field3'])
Query Items
Add the query to get function.
Query can be object or array.
General rules:
=:field: value!=:field: {ne: value}.nestands for "not equal">:field: {gt: value}.gtstands for "greater than"<:field: {lt: value}.ltstands for "lower than">=:field: {ge: value}.gestands for "greater or equals to"<=:field: {le: value}.lestands for "greater or equals to"- AND: curly brace
{A, B, C}read as "A and B and C" - OR: square brace
[A, B, C]read as "A or B or C"
Examples:
Get all items where column col1 is equal to 123
sheet.get('Sheet1', {'col1': 123})
Get all items where column col1 == 123 AND col2 == 456
sheet.get('Sheet1', {'col1': 123, 'col2': 456})
Get all items where column col1 == 123 OR col1 == 456
sheet.get('Sheet1', [{'col1': [123, 456]}])
// OR
sheet.get('Sheet1', [{'col1': 123}, {'col1': 456}])
Get all items where column col1 > 123
sheet.get('Sheet1', {'col1': {'gt': 123}})
Get all items where column col1 < 123
sheet.get('Sheet1', {'col1': {'lt': 123}})
Get all items where column col1 >= 123
sheet.get('Sheet1', {'col1': {'ge': 123}})
Get all items where column col1 >= 123
sheet.get('Sheet1', {'col1': {'ge': 123}})
Get all items from interval col1 > 123 AND col1 <= 456 (for short (123, 456])
sheet.get('Sheet1', {'col1': {'gt': 123, le: 456}})
Get all items where col1 belongs to interval (1, 3] OR from interval [14, 16)
sheet.get('Sheet1', {'col1': [{'gt': 1, le: 3}, {'ge': 14, 'lt': 16}]})
Get all items where col1 == 30 OR belongs to interval (1, 3] OR to interval [14, 16)
sheet.get('Sheet1', {'col1': [30, {'gt': 1, 'le': 3}, {'ge': 14, 'lt': 16}]})
Auth (Optional)
Create a table _user with the following columns:
-
id to identify each user.
-
token or username and password depending on how you want to do the login.
-
permission should contain either
admin,userorblocked(default).admincan read (r), write (w) and delete (x) access to all tables.usercan only read recursively tables that reference its user'sid.blockedcan not do rwx.
-
read allow or disable read to tables, give their names splited by ",".
-
write allow or disable write to tables, give their names splited by ",".
-
delete allow or disable delete to tables, give their names splited by ",".
You can change the name of Auth table here.
Get auth info
sheet.me()
Example
Table: _user
| id | token | permission | read | write | delete |
|---|---|---|---|---|---|
| 1 | user01 | admin | Table3 | ||
| 2 | user02 | user | |||
| 3 | user03 | block | Table3 |
Table: Table1
| id | _user | col1 | Table2 |
|---|---|---|---|
| 10 | 2 | 123 | 456 |
| 11 | 4 | 321 | 789 |
Table: Table2
| id | my_data |
|---|---|
| 456 | 123 |
Table: Table3
| id | temperature |
|---|---|
| 14 | 43.4 |
user01 can read, write and delete items from all tables except delete Table3.
user02 can not get Table2 directly, instead he can ask Table1, because it has a reference to him (by its user's id). By asking Table1 he will only get the entries where column _user contains its user's id. In this example he will get the entry id == 10. This entry has the column Table2 which references to a valid entry on Table2, so he will get this entry as well. Note that he has no access to Table3.
user03 is blocked by default he can only read Table3.
Metadata
Release files for gsheetdb 1.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gsheetdb-1.2.4.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gsheetdb-1.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.2 kB
Release files / gsheetdb-1.2.4.tar.gz
| Download URL | gsheetdb-1.2.4.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
913c16f1e4f43e3988d8926fda423a4dd5377045a199af10cff76bcf75feedfb
|
|
BLAKE2b-256 checksum How to use checksums |
94e3b670c97654114f93e9af16fa19fce3cd797fba4d19391981a47a9d968120
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / gsheetdb-1.2.4-py3-none-any.whl
| Download URL | gsheetdb-1.2.4-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f472f596fa452702dbfbf67a257e93bc73c1d8a1c8884facbf86447428992405
|
|
BLAKE2b-256 checksum How to use checksums |
fddff9c183f564f2fba1e05d52eacfb4e07590a0743e86d771a66563955bb29c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|