betodealmeida/gsheets-db-api

Open spreadsheet as database, worksheets as tables?

jrjsmrtn opened this issue · 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