Skip to main content

Google spread sheet as dictionary list. read-only.

Project description

Google spreadsheet as dictionary list. read-only.

Preparation

Google API Console

Make credentials on Google spreadsheet.

https://console.developers.google.com/apis/dashboard

Credentials -> Create credentials -> Service account key

Download credential as JSON.

Google spreadsheet

Open google spreadsheet.

Share -> Input email in credential file

xxxxxxxxxxxx@appspot.gserviceaccount.com

Usage

from gspreaddict import GSpreadDict

class TestRecord(GSpreadDict):
    spreadsheet_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    credentials_json_path = os.path.join(
        os.path.dirname(__file__), "My Project-xxxxxxxx.json")

spreadsheet_key is in Google spreadsheet URL.

credentials_json_path is downloaded Json credentials path.

Get instances,

record = TestRecord.objects.get(key=value))
record = TestRecord.objects.get(lambda x: x['key'] == value)

Caching

from django.core.cache import caches

class TestRecord(GSpreadDict):
    spreadsheet_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    credentials_json_path = os.path.join(
        os.path.dirname(__file__), "My Project-xxxxxxxx.json")

@classmethod
def cache_set(cls, key, value):
    caches['gspreaddict'].set(key, value)

@classmethod
def cache_get(cls, key):
    return caches['gspreaddict'].get(key)

Override cache_set and cache_get classmethods.

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

python-gspreaddict-0.1.0.tar.gz (3.0 kB view hashes)

Uploaded Source

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