Error occured in connecting streamlit with public google sheets

I want to connect my streamlit app with public google sheets.

Therefore i had followed some pre-requisites Connect Streamlit to a public Google Sheet.

Following are some pre-requisite i have adhered:

  • Creation of .streamlit/secrets.toml file & pasted sheet url link inside it.

  • Added gsheetsdb==x.x.x version to requirements.txt file.

Following is public google sheet.

Following is code:

import streamlit as st
from gsheetsdb import connect

# Create a connection object.
conn = connect()

# Perform SQL query on the Google Sheet.
# Uses st.cache to only rerun when the query changes or after 10 min.
def run_query(query):
    rows = conn.execute(query, headers=1)
    rows = rows.fetchall()
    return rows

sheet_url = st.secrets["public_gsheets_url"]
rows = run_query(f'SELECT * FROM "{sheet_url}"')

# Print results.
for row in rows:
    st.write(f" User: {row.Email} has password :{row.Password}:")

I am getting following errors:

ImportError: cannot import name 'Iterable' from 'collections' (C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\collections\
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\streamlit\runtime\scriptrunner\", line 564, in _run_script
    exec(code, module.__dict__)
File "C:\Users\User\Desktop\Development\Minor Project\Sentiment Analysis Web APP\", line 2, in <module>
    from gsheetsdb import connect
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\gsheetsdb\", line 1, in <module>
    from gsheetsdb.db import connect
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\gsheetsdb\", line 11, in <module>
    from gsheetsdb.query import execute
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\gsheetsdb\", line 11, in <module>
    from moz_sql_parser import parse as parse_sql
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\moz_sql_parser\", line 15, in <module>
    from moz_sql_parser.sql_parser import SQLParser, scrub_literal, scrub
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\moz_sql_parser\", line 12, in <module>
    from mo_parsing.engine import Engine
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\mo_parsing\", line 60, in <module>
    from mo_parsing.infix import LEFT_ASSOC, RIGHT_ASSOC, infixNotation
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\mo_parsing\", line 4, in <module>
    from collections import Iterable

I am doing my graduation minor project using streamlit please help me out. Your help will really be appreciable. :pray:

Take a look at tha readme file of gsheetsdb.

1 Like

Thankyou so much @Goyo for replying.
After implementing below code:

import streamlit as st
#from gsheetsdb import connect
from shillelagh.backends.apsw.db import connect
conn = connect()
result = conn.execute("""
""", headers=1)
for row in result:

I am getting below error:

TypeError: connect() missing 1 required positional argument: 'path'
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\streamlit\runtime\scriptrunner\", line 564, in _run_script
    exec(code, module.__dict__)
File "C:\Users\User\Desktop\Development\Minor Project\Sentiment Analysis Web APP\", line 23, in <module>
    conn = connect()

Please help me rectify this one as well.
which path should mention inside connect() function

I guess ":memory:" should do.

I am having the same issue. after adding “::memory::”

I get the following error:

InterfaceError: Unable to load adapter datasetteapi


File "/usr/local/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/", line 565, in _run_script
    exec(code, module.__dict__)File "/Users/asifk/Documents/github/portfolio/pages/7_✨", line 19, in <module>
    connection = connect(":memory:")File "/usr/local/lib/python3.10/site-packages/shillelagh/backends/apsw/", line 521, in connect
    enabled_adapters = registry.load_all(adapters, safe)File "/usr/local/lib/python3.10/site-packages/shillelagh/adapters/", line 58, in load_all
    return self._load_all_safe(adapters) if safe else self._load_all(adapters)File "/usr/local/lib/python3.10/site-packages/shillelagh/adapters/", line 91, in _load_all
    return {File "/usr/local/lib/python3.10/site-packages/shillelagh/adapters/", line 92, in <dictcomp>
    name: self.load(name, safe=False)File "/usr/local/lib/python3.10/site-packages/shillelagh/adapters/", line 44, in load
    raise InterfaceError(f"Unable to load adapter {name}")
1 Like

I’m having same issue as khushnoodasis… let me know if you found a fix.

There is an issue with shillelagh that requires you to install a number of extra packages before it actually works with google sheets. pip install 'shillelagh[all]' should fix it, if you don’t mind extra packages.

However, there is a new simpler method simply using pandas in the just-updated tutorial Connect Streamlit to a public Google Sheet - Streamlit Docs

csv_url = sheets_url.replace("/edit#gid=", "/export?format=csv&gid=")
return pd.read_csv(csv_url)
1 Like

Installing shillelagh[gsheetsapi] is probably enough (didn’t test it myself).

It should be enough, but there seems to be a bug in shillelagh that assumes the url is a datasette url, so it fails unless datasette is installed also. Installing those two is sufficient, even though gsheetsapi should be sufficient, but [all] gets you everything you need for sure :slight_smile:

1 Like

How would this work for a private google sheet? E.g., how to pass the credentials? I would love to be able to load into a pandas dataframe like this instead of querying the sheet.

1 Like

@sudo_reboot You can see an example Connect Streamlit to a private Google Sheet - Streamlit Docs of how to set up the credentials, which should also work with shillelagh.