Skip to main content

GOogle SHeets DataBase - Python client to key-value database based on Google Sheets

Project description

goshdb

GOogle SHeets DataBase - Python client to key-value database based on Google Sheets

Sheet works as a table and has the following structure:

| key | value |
|-----|-------|
|     |       |
|     |       |
|     |       |

Installation

pip install goshdb

Configuration

Step 1. Select a Google account that will be used to access the spreadsheet

Details
  • Though Table uses only provided spreadsheet, credentials technically allow to read/write all the spreadsheets in the account.
  • So it's recommended to use Table with a special service (non-personal) account that doesn't have critical/secret spreadsheets that might be compromised.

Step 2. Obtain credentials.json file with this the instruction

Details
  • If you do this for the first time - take credentials.json and put it in secret_dir.
  • On a first attempt to create Table it'll open a browser window, ask you to sign in the target test account.
  • Then the token.json file will be generated automatically and put in secret_dir.
  • The token.json file will be used automatically for further access to the target spreadsheet.
  • You can use token.json to access the spreadsheet from another machine without completing the steps above

Step 3. Create a spreadsheet in your Google Sheets account.

Details
  • You should share the spreadsheet and provide write access to the account that will be used to access it (see Step 1).

Usage

from goshdb import Table
from pathlib import Path

# Take spreadsheet ID from your spreadsheet URL:
# https://docs.google.com/spreadsheets/d/[SPREADSHEET_ID]/edit#gid=0
SPREADSHEET_ID = '...'
# Provide a sheet name. It should be either new sheet or existing one that follows the required structure.
SHEET_NAME = '...'  


# Create a Table object. If you do this for the first time - it'll open a browser window (see Step 2 details)
table = Table(
    secret_dir=Path('path/to/secret_dir'),
    spreadsheet_id=SPREADSHEET_ID,
    sheet_name=SHEET_NAME
)

# Write a key-value pair
table.set_string('city', 'London')
print(table.get_string('city'))  # London
table.set_object('person_1', {'name': 'John', 'age': 30})
print(table.get_object('person_1'))  # {'name': 'John', 'age': 30}

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

goshdb-0.1.0.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

goshdb-0.1.0-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

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