Skip to main content

A simple way to use Google Sheet as your Data Base.

Project description

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

  1. Create a google sheet
  2. Add as many sheets (tables) as you want
  3. First line is table header, first column must be id
  4. Table relationship: set a column header with the name of a table, its content is the id (or ids) of the other table
  5. Go to "Extensions > App Script"
  6. Copy the content of the file gsheet.js to the current file.
  7. 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"
  8. Copy Deployment ID

Usage

from gsheetdb import Sheet

const sheet = Sheet({ 'deploymentId': '123456789abcdef' })

Get Tables (with Schemas)

sheet.tables();

Add Item

Ids are generated automaticaly

sheet.set('Sheet1', [
    {'col1': 'val1', 'col2': 2, 'col3': datetime.datetime()},
    {'col1': 'val2', 'col2': 3, 'col3': datetime.datetime()},
])

Get Item

Return all items

const data = sheet.get('Sheet1')

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}. ne stands for "not equal"
  • >: field: {gt: value}. gt stands for "greater than"
  • <: field: {lt: value}. lt stands for "lower than"
  • >=: field: {ge: value}. ge stands for "greater or equals to"
  • <=: field: {le: value}. le stands 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:

  1. id to identify each user.

  2. token or username and password depending on how you want to do the login.

  3. permission should contain either admin, user or blocked (default).

    • admin can read (r), write (w) and delete (x) access to all tables.
    • user can only read recursively tables that reference its user's id.
    • blocked can not do rwx.
  4. read allow or disable read to tables, give their names splited by ",".

  5. write allow or disable write to tables, give their names splited by ",".

  6. delete allow or disable delete to tables, give their names splited by ",".

You can change the name of Auth table here.

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.

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

gsheetdb-1.2.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gsheetdb-1.2.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file gsheetdb-1.2.1.tar.gz.

File metadata

  • Download URL: gsheetdb-1.2.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gsheetdb-1.2.1.tar.gz
Algorithm Hash digest
SHA256 c8f4d6739674fc3bb830cf6cf7b24498a5cc466cb9098e2a80f3db49d4b60892
MD5 063c66a409a6d5a90fd11ad40fbb2a17
BLAKE2b-256 bde538203bcc8d6f2b3992c5104de8205859e31c3b164b42d6340d445b0c7256

See more details on using hashes here.

File details

Details for the file gsheetdb-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: gsheetdb-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gsheetdb-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 19c7c48873df7a52af3ace8cfe283e005fc5662ad565f876df8a7d574a9a4730
MD5 1e2d1ba79b2a68e3784e726e9225828f
BLAKE2b-256 797d575ec4b00b3aad2b6c78f69fe5677da5dae3b3c59be72e855e423382a43c

See more details on using hashes here.

Supported by

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