Downloading a google drive folder for deployed streamlit app

I am trying to download a google drive folder within my streamlit app. I am able to get it to work locally but not when deployed. I am using this library Google-Drive-Folder-Downloader to download the folder and it’s contents. I am unsure how to adapt this library to work with Streamlit. I seem to be able to get the credentials working but then it does not seem like my program can “see” any files in my drive… I was able to get this library to work locally, but then when I adapted it for Streamlit via the Private Google Sheets method, it stopped working. Any advice or help would be greatly appreciated.

Hi @Z_Margulies -

My guess would be that you are using a function from that library that is expecting to see a JSON file, but st.secrets is providing the actual data.

Can you provide a link to the code you are running (not the secrets, just the Python code).


Hi @randyzwitch thanks so much. Absolutely, so I have been using this : Google-Drive-Folder-Downloader/ at master · Willena/Google-Drive-Folder-Downloader · GitHub

I have attempted to adapt the code for streamlit and I believe I have successfully got the drive to connect, but I still cannot get my app to see or download files from the google drive. Before adapting this to the st.secrets format, I was able to get this script to work locally by making use of a json file. I appreciate all your help in advance!

I can almost guarantee that the error is somewhere around here:

This library assumes you have a JSON file; this will not be the case on Streamlit Cloud. Rather, st.secrets provides a dict-like object having keys and values, the data inside the JSON file.

What you need to do is use the base Google libraries that the code snippet you linked to uses, and find a function similar to from_client_secrets_file, but that lets you pass the credentials in directly. In the private Google Sheet example you link to, that’s what this code snippet is doing:

import streamlit as st
from google.oauth2 import service_account
from gsheetsdb import connect

# Create a connection object.
credentials = service_account.Credentials.from_service_account_info(
conn = connect(credentials=credentials)


1 Like

Amazing! Thank you Randy.

Do you have any idea of of the function that that might be similar to from_client_secrets_file might be?

@randyzwitch This thread is closest thing I can find to an answer but I am just not sure how to make it work for my instance. python - How to use the Google API without checking a client_secret.json into version control? - Stack Overflow