Skip to content

Instantly share code, notes, and snippets.

@myedibleenso
Last active August 29, 2025 00:13
Show Gist options
  • Select an option

  • Save myedibleenso/b8c0ebb9817bd818751dca0163480e3e to your computer and use it in GitHub Desktop.

Select an option

Save myedibleenso/b8c0ebb9817bd818751dca0163480e3e to your computer and use it in GitHub Desktop.
Google Sheet -> sqlite DB

The URL structure to download a Google sheet to a csv is https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=yourDocId&exportFormat=csv&sheet=1

The URL structure to view a Google shet is https://docs.google.com/spreadsheets/d/yourDocId

import pandas as pd

mk_gsheets_url = lambda doc_id: f"https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key={doc_id}&exportFormat=csv"

df = pd.read_csv(mk_gsheets_url("1sVvfAGxBdr2R2aiCkG4_STAvIJLBwH3HTADElsagey4"))

# connect to database
import sqlite3

db_name = "lynch"
conn = sqlite3.connect(f"{db_name}.db")

# push the dataframe to sql 
df.to_sql(name=db_name, con=conn, if_exists="replace")

# display contents of table
conn.execute(f"SELECT * FROM '{db_name}';").fetchall()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment