Skip to main content

A tiny library for one-way syncing the Google spreadsheet to database

Project description

Sheet2db

Sheet2db is a tiny python library for one-way syncing the Google spreadsheet to database. (Currently, it supports only MySQL)

It is useful for managing some static data on Google spreadsheet, but also want to sync the sheet data to database.

Sheet2db DOES NOT collect any your secret values!

Installation

pip install sheet2db

Usage

You must have API key which is accessible to Google Spreadsheet API

Example sheet format (items tab):

===========================
|  A |    B |     C |   D |
===========================
| id | name | count | ver |
|----|------|-------|-----|
| .. | .... | ..... | ... |
===========================

Following example will sync items tab of 1U3un2ZJPRhLrWzc2DMXq8VI7Nqf9pYlajfO4mQVCZpE spreadsheet to database:

"AIzaSyC6pabjqmaPiguYoHbq4W7a0DV0wQg5JGk" is a fake api key

from sheet2db import Sheet2db

# Pass API key
syncer = Sheet2db(api_key='AIzaSyC6pabjqmaPiguYoHbq4W7a0DV0wQg5JGk')

# If you need to access to private spreadsheet, you can't use API key. Use oauth credentials instead.
syncer = Sheet2db(
    creds_path='credentials.json',
    token_path='token.json')

# Fetch data from spreadsheet
syncer.fetch(
    sheet='1U3un2ZJPRhLrWzc2DMXq8VI7Nqf9pYlajfO4mQVCZpE',
    tab='items',
    range='A1:D')

# Sync fetched data to database (mysql)
syncer.sync(
    host='192.168.168.10',
    port=3306,
    user='mingrammer',
    password='p@ssw0rd',
    db='static',
    table='items')

You can also use ssh tunneling to access to remote database with sshtunnel

with sshtunnel.SSHTunnelForwarder(
    ('db.service.io', 22),
    ssh_username='ssh_user'
    ssh_pkey='~/.ssh/id_rsa'
    ssh_private_key_password='ssh_pk_password',
    remote_bind_address=('localhost', 3306),
) as tunnel:
    syncer.sync(
        host = tunnel.local_bind_host,
        port = tunnel.local_bind_host,
        user = 'mingrammer',
        password = 'p@ssw0rd',
        db = 'static',
        table = 'items')

License

MIT

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

sheet2db-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

sheet2db-1.0.0-py2.py3-none-any.whl (3.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sheet2db-1.0.0.tar.gz.

File metadata

  • Download URL: sheet2db-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for sheet2db-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d8edaf224c3adfa72c15d5849a635b67e11ca08b697c1c5ccbd5fee751fa8b91
MD5 68afaee980131ebfd3ddad40f67193e1
BLAKE2b-256 e5405b9f272c06a6dcc372f421382401c4e51384dead9c9470b72b92de338ac1

See more details on using hashes here.

File details

Details for the file sheet2db-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sheet2db-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for sheet2db-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3afa32698f651e8dae5459757ea0c58d9689d7ff94267f527aade0caf29ace7e
MD5 09c2597776a7daf31e796cd0b4117436
BLAKE2b-256 997719beeb17953bea1644483ce84125596caa5c56cda171eb45811af67d0228

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