Skip to main content

Streamlit component for picking files from Google Drive

Project description

streamlit-google-picker

A Streamlit component to select files and folders from Google Drive using the official Google Picker.

This component lets you embed the Google Drive file picker directly in your Streamlit app, allowing your users to select files or folders from their Google Drive and work with them as Python file-like objects.


🚀 Features

  • Pick files or folders from Google Drive
  • Multi-select support (pick multiple files/folders at once)
  • Filter by file type or MIME type (e.g. PDF, images, etc.)
  • Folder navigation just like Drive (In progress)
  • Native Streamlit feel, like st.file_uploader

📸 Demo


🛠️ Installation

pip install streamlit-google-picker

For latest dev, use pip install git+https://github.com/LounesAl/streamlit-google-picker


⚙️ Requirements

You need a Google Cloud project with proper OAuth2 and API setup:

  1. Create an OAuth2 Client ID (Web application)
  2. Set Redirect URI (e.g. http://localhost:8501 for local)
  3. Enable both Google Drive API and Google Picker API

Set these in your environment:

GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_API_KEY=your-api-key
GOOGLE_PROJECT_NUMBER=your-project-number

✨ Usage

After the user is authenticated (OAuth2, see examples), use the picker:

import streamlit as st
from streamlit_google_picker import google_picker

token = st.session_state["token"]["access_token"]  # From your OAuth2 flow
API_KEY = os.environ["GOOGLE_API_KEY"]
APP_ID = os.environ["GOOGLE_PROJECT_NUMBER"]

uploaded_files = google_picker(
    label="Pick files from Google Drive",
    token=token,
    apiKey=API_KEY,
    appId=APP_ID,
    accept_multiple_files=True,
    type=["pdf", "png", "jpg"],   # file extensions or MIME types
    allow_folders=True,
    nav_hidden=False,
    key="google_picker",
)

if uploaded_files:
    for uploaded_file in uploaded_files:
        st.write(f"Filename: {uploaded_file.name}, Size: {uploaded_file.size_bytes}")
        # To get file content:
        data = uploaded_file.read()  # This downloads the file on-demand!
        # Display or process as needed
        st.write(f"Bytes: {len(data)}")

Folder selection: If the user selects a folder, all files inside (recursively) are returned as UploadedFile objects.

You can also use it with a single file (returns a single object or None):

uploaded_file = google_picker(accept_multiple_files=False, ...)
if uploaded_file:
    st.write(uploaded_file.name)
    content = uploaded_file.read()

📥 Return Format

  • If accept_multiple_files=True, returns a list of UploadedFile objects (like Streamlit’s).
  • If accept_multiple_files=False, returns a single UploadedFile or None.

Each UploadedFile behaves like a Python file object (subclass of io.BytesIO):

uploaded_file.name       # Original filename
uploaded_file.size_bytes # File size in bytes
uploaded_file.type       # MIME type
uploaded_file.url        # Direct Google Drive URL
uploaded_file.id         # File ID
uploaded_file.read()     # Reads bytes (downloads on demand)

🧩 Full OAuth2 + Picker Example

A typical flow:

  1. User authenticates via Google OAuth2 (e.g. with streamlit-oauth)
  2. Store access_token in st.session_state
  3. Pass token to google_picker()
  4. Get uploaded files as file-like objects

See example.py for a full sample.


🧑‍💻 Development

  • Clone this repo
  • Install backend (Python) and frontend (React) requirements
  • Run npm install && npm start in frontend/ for hot-reload
  • Develop Streamlit component as usual

📜 License

MIT


💡 Credits


Found a bug or have a feature request? Open an issue!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_google_picker-0.1.0.tar.gz (134.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_google_picker-0.1.0-py3-none-any.whl (133.5 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_google_picker-0.1.0.tar.gz.

File metadata

  • Download URL: streamlit_google_picker-0.1.0.tar.gz
  • Upload date:
  • Size: 134.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for streamlit_google_picker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ecb3b705b03d4a8af8ed5e6068a075e6a183821a2930382f02927bd8b1d5f562
MD5 98e28ac1f6a381b6e3e4f6d85ceecbfd
BLAKE2b-256 e0b297e1055a5cb85172343127c33f36ae1db80ded676b4fc36d684d35cbf140

See more details on using hashes here.

File details

Details for the file streamlit_google_picker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_google_picker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd5ff6773f6f8746c611d65317622ac9bd2203d978c92b53887361b8119dd2ae
MD5 2aee4aa147738d5f301cba8c3df21ff9
BLAKE2b-256 5e582fa0683efc5132daa46a201b7927de3685f7fdc773dd233fc550e9cf64d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page