<aside> ⚠️ DEPRECATED!!! This guide migrated to our docs. Please view the current version at: https://docs.streamlit.io/en/stable/tutorial/public_gsheet.html
</aside>
This guide explains how to securely access a public Google Sheet from Streamlit sharing or Streamlit for Teams. It uses the gsheetsdb library and Streamlit's secrets management (requires streamlit v0.80.0 or higher).
<aside> ☝ This method requires you to enable link sharing for your Google Sheet. While the sharing link will not appear in your code (and actually acts as sort of a password!), someone with the link can get all the data in the Sheet. If you don't want this, follow the (more complicated) guide Connecting Streamlit to a private Google Sheet .
</aside>
<aside> 🏃 If you already have a Sheet that you want to access, feel free to skip this step. Also, you can just use the example Sheet given in step 2.
</aside>
Your local Streamlit app will read secrets from a file .streamlit/secrets.toml
in your app's root dir. Create this file if it doesn't exist yet and add the share link of your Google Sheet to it as shown below:
# .streamlit/secrets.toml
public_gsheets_url = "<https://docs.google.com/spreadsheets/d/xxxxxxx/edit#gid=0>"
<aside>
☝ Add this file to .gitignore
and don't commit it to your Github repo!
</aside>
As the secrets.toml
file above is not commited to Github, you need to pass its content to your deployed app (on Streamlit sharing or Streamlit for Teams) separately. Go to the app dashboard and in the app's dropdown menu, click on Edit Secrets. Copy the content of secrets.toml
into the text area. More infos in Secrets Management.
pip install gsheetsdb
Add the package to your requirements.txt
file, preferably pinning its version (just replace x.x.x
with the version you installed):
# requirements.txt
gsheetsdb==x.x.x