Edit page in Livemark
(2022-09-19 18:33)

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

Signature

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

Parameters

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

formats.gsheetsControl.credentials (property)

NOTE: add docs

Signature

Optional[str]

It's a beta version of Frictionless Framework (v5). Read Frictionless Framework (v4) docs for a version that is currently installed by default by pip.