Google Sheets

Getting Started

To use Google Sheets as a data source, you will need to install the gspread and oauth2client Python packages. You can install this package using pip:

pip install gspread oauth2client


Service Account Key File

To authenticate with Google Sheets, you will need to create a service account and download the service account key file. You can create a service account and download the key file by following the instructions here.

Once you have downloaded the key file, you can authenticate with Google Sheets by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of the key file:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key/file.json

Reading Data

To read data from Google Sheets, you will need to authenticate and create a gspread.Client. You can then use this object to read data from Google Sheets.

# Cell 1 - Load libraries
import marimo as mo
import pandas as pd
import os
import gspread
from oauth2client.service_account import ServiceAccountCredentials

# Authenticate with Google Sheets
scope = [
credentials = ServiceAccountCredentials.from_json_keyfile_name(
gc = gspread.authorize(credentials)

# Cell 2 - Load the sheet
wks ="marimo").sheet1


Check out our full example using Google Sheets here

Or run it yourself:

marimo run