Tag: gspread
TIL: A DictWriter interface for Google Spreadsheets August 21st, 2023
I’ve been using Python’s csv library approximately forever so its interfaces – particularly the DictReader and DictWriter interfaces – are almost literally muscle memory at this point. So when I needed to push a bunch of data to Google Sheets, I naturally wanted an interface that worked like DictWriter. Here’s the code: class WorksheetDictWriter: """ Something like a `csv.DictWriter`, except for a `gspread.Worksheet` """ def __init__(self, worksheet: gspread.Worksheet, fieldnames: list[str], column="A"): self.…
TIL: Stop storing credentials in plaintext part #624: gspread edition August 18th, 2023
Here’s how to safely store and use credentials for the Python gspread library, a Python API for Google Sheets. Background: How To Keep A Secret, by Glyph The most relevant parts start around 15:00, but watch the whole thing, it’s great and worth your time. Pre-requisites Install keyring: pip install keyring or equivalent. Storing credentials Create service account credentials as explained in the gspread docs. This ends with you having a JSON credentials file on your disk somewhere (unacceptable).…