Google Sheets

Note

This functionality is available, when collabutils is installed with the googlesheets extra, i.e. via

pip install collabutils[googlesheets]

Google Sheets provides a good platform to curate tabular data collaboratively. Thus, we can use it to work on input for CLDF datasets, such as language metadata. This module provides functionality to pull such data from Google Sheets, suitable for inclusion in cldfbench download command implementations.

We use the gspread library to interact with data in Google Sheets. Thus, code needs access to a JSON OAuth2 key file to authenticate it. Retrieving such a key file (and giving permissions to the corresponding service account for particular sheets) is described at https://docs.gspread.org/en/latest/oauth2.html.

Thus, everyone running cldfbench download for a dataset using Google Sheets, would need (access to) a JSON OAuth2 key file with appropriate authorizations.

class collabutils.googlesheets.Spreadsheet(key_or_url, auth=None)[source]

Typical usage in a cldfbench.Dataset’s cmd_download method:

>>> document = Spreadsheet('doc-key', auth='credentials.json')
>>> document.fetch_sheets(
...     sheets={'Varieties': 'languages.tsv'})
...     outdir=dataset.etc_dir,
...     delimiter='     ')
Parameters
  • key_or_url (str) –

  • auth (typing.Union[pathlib.Path, str, None]) –

fetch_sheets(sheets=None, outdir='.', **kw)[source]
Parameters
  • sheets (typing.Optional[typing.Dict[str, str]]) – A mapping of sheet titles to filenames, specifying which sheets to save in which files. If None, all sheets will be saved to files “sheet_<no>.csv”.

  • outdir (typing.Union[pathlib.Path, str, None]) –

  • kw – Passed as kwargs into UnicodeWriter.