Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gsheetsdbを試す #62

Closed
ftnext opened this issue Aug 27, 2021 · 2 comments
Closed

gsheetsdbを試す #62

ftnext opened this issue Aug 27, 2021 · 2 comments
Assignees

Comments

@ftnext
Copy link
Owner

ftnext commented Aug 27, 2021

https://github.com/betodealmeida/gsheets-db-api

gspreadですべての値を取ってくることが多いが、SQLで取れるツールがあることを知った
ref: https://docs.streamlit.io/en/stable/tutorial/private_gsheet.html

@ftnext ftnext self-assigned this Aug 27, 2021
@ftnext
Copy link
Owner Author

ftnext commented Aug 27, 2021

分かったこと

公開しているスプレッドシートの読み取りはサンプルコードの通り

限定公開のスプレッドシートは、Streamlitのドキュメントが参考になる。
gsheetsdbのREADMEに記載のあるauth(辞書)を使う方法は動作しなかった

AttributeError: 'dict' object has no attribute 'before_request'

from google.oauth2 import service_account
from gsheetsdb import connect

credentials = service_account.Credentials.from_service_account_file(
    /path/to/service_account.json,
    scopes=[
        "https://www.googleapis.com/auth/spreadsheets",
    ],
)
conn = connect(credentials=credentials)

@ftnext
Copy link
Owner Author

ftnext commented Aug 27, 2021

Future works

ただし、読み取り限定(SELECTしかサポートしない)

mo_parsing.exceptions.ParseException: Expecting select, found "UPDATE\n " (at char 13, (line:2, col:13)

betodealmeida/gsheets-db-api#13 が挙がっているが未マージ
(フォークしたリポジトリからインストールすることも考えられるが、テストコードがないのがネック)

https://github.com/betodealmeida/shillelagh はUPDATEもサポート。
gsheetsdbのREADME冒頭でも乗り換えを案内している。
プライベートなスプレッドシートへの接続方法が確認できれば使える

You can even run INSERT/DELETE/UPDATE queries against the spreadsheet:

SQLAlchemyもスプレッドシートへの接続をサポートする??
https://github.com/betodealmeida/shillelagh/blob/a96c08f91f895e240a0d517fcdfc57c63f4b0009/docs/adapters.rst#custom-dialect
create_engine("gsheets://", service_account_file="/path/to/credentials.json")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant