Edit page in Livemark
(2024-12-13 12:49)

Gsheets Format

Frictionless supports parsing Google Sheets data as a file format.

pip install frictionless[gsheets]
pip install 'frictionless[gsheets]' # for zsh shell

Reading Data

You can read from Google Sheets using Package/Resource, for example:

from pprint import pprint
from frictionless import Resource

path='https://docs.google.com/spreadsheets/d/1mHIWnDvW9cALRMq9OdNfRwjAthCUFUOACPp0Lkyl7b4/edit?usp=sharing'
resource = Resource(path=path)
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': '中国人'}]

Writing Data

The same is actual for writing:

from frictionless import Resource, formats

control = formats.GsheetsControl(credentials=".google.json")
resource = Resource(path='data/table.csv')
resource.write("https://docs.google.com/spreadsheets/d/<id>/edit", control=control})

Configuration

There is a dialect to configure how Frictionless read and write files in this format. For example:

from frictionless import Resource, formats

control = formats.GsheetsControl(credentials=".google.json")
resource = Resource(path='data/table.csv')
resource.write("https://docs.google.com/spreadsheets/d/<id>/edit", control=control)

Reference

formats.GsheetsControl (class)

formats.GsheetsControl (class)

Gsheets control representation. Control class to set params for Gsheets api.

Signature

(*, name: Optional[str] = None, title: Optional[str] = None, description: Optional[str] = None, credentials: Optional[str] = None) -> None

Parameters

  • name (Optional[str])
  • title (Optional[str])
  • description (Optional[str])
  • credentials (Optional[str])

formats.gsheetsControl.credentials (property)

API key to access google sheets.

Signature

Optional[str]