<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>

Introduction

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>

Step 1: Create a Google Sheet and turn on link sharing

<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>

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5f87168f-8410-4d35-8a1f-11c3a9489ee3/Screenshot_2021-04-14_at_04.06.05.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/2c1e74aa-f321-4911-99ce-7f50a798e038/Screenshot_2021-04-14_at_04.06.19.png

Step 2: Add the Sheets URL to your local app secrets

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>

Step 3: Copy your app secrets to the cloud

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.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/24e1199d-f19e-40c6-b4f5-c0f4598556de/Screenshot_2021-05-04_at_19.01.58.png

Step 4: Install gsheetsdb and add it to your requirements file

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