gsheets-db-api icon indicating copy to clipboard operation
gsheets-db-api copied to clipboard

Open spreadsheet as database, worksheets as tables?

Open jrjsmrtn opened this issue 6 years ago • 0 comments

Wouldn't it be easier to open the Google spreadsheet as a database, then use worksheets as tables? And eliminate the need for an intermediate catalog?

Like this:

from sqlalchemy import *
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import *

engine = create_engine("gsheets://1_rN3lm0R_bU3NemO0s9pbFkY5LQPcuy1pscv8ZXPtg8")
inspector = inspect(engine)

table = Table(
    "Simple sheet",
    MetaData(bind=engine),
    autoload=True)
query = select([func.count(table.columns.country)], from_obj=table)
print(query.scalar())  # prints 3.0

jrjsmrtn avatar Oct 08 '19 15:10 jrjsmrtn