Skip to main content

Sheetfu is a library to interact with Google sheets.

Project description

https://travis-ci.org/socialpoint-labs/sheetfu.svg?branch=master

Sheetfu was built to interacts with Google Sheets with a simple, intuitive, and fast API. The primary goal of this library is to adapt the Google App Script API for spreadsheets, to Python. With Sheetfu, you can easily get or set cell values, background colors, font colors or any other cell attributes.

Installing

Install and update using pip:

pip install -U sheetfu-dev

A Simple Example

from sheetfu import SpreadsheetApp

sa = SpreadsheetApp('path/to/secret.json')
spreadsheet = sa.open_by_id('<insert spreadsheet id here>')
sheet = spreadsheet.get_sheet_by_name('Sheet1')
data_range = sheet.get_data_range()           # returns the sheet range that contains data values.

# this is how you get things
values = data_range.get_values()              # returns a 2D matrix of values.
backgrounds = data_range.get_backgrounds()    # returns a 2D matrix of background colors in hex format.

# this is how you set things
data_range.set_background('#000000')          # set every cell backgrounds to black
data_range.set_font_color('#ffffff')          # set every cell font colors to white

For better security, you can also create your SpreadsheetApp object with environment variables instead of the secrets.json file.

To obtain your secret json file and know more about how to initialize your ENV vars, you can refer to the authentication tutorial.

You can refer to the sheetfu API documentation for a more detailed description.

The Table module

Sheetfu also contains a table module that abstracts completely the coordinates system for an ORM-like syntax. The example below is for a sheet with the 3 columns ‘name’, ‘surname’ and ‘age’.

from sheetfu import Table

spreadsheet = SpreadsheetApp('path/to/secret.json').open_by_id('<insert spreadsheet id here>')
data_range = spreadsheet.get_sheet_by_name('people').get_data_range()

table = Table(data_range, backgrounds=True)

for item in table:
    if item.get_field_value('name') == 'foo':
        item.set_field_value('surname', 'bar')              # this set the surname field value
    age = item.get_field_value('age')
    item.set_field_value('age', age + 1)
    item.set_field_background('age', '#ff0000')             # this set the field 'age' to red color

# Every set functions are batched for speed performance.
# To send the batch update of every set requests you made,
# you need to commit the table object as follow.
table.commit()

You can refer to the Table API documentation for a more detailed description.

Contributing

For guidance on how to make a contribution to Sheetfu, see the contributing guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

sheetfu_dev-1.5.4.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file sheetfu_dev-1.5.4.0-py3-none-any.whl.

File metadata

  • Download URL: sheetfu_dev-1.5.4.0-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for sheetfu_dev-1.5.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 978c4e555fa4bd51cc056f209f60aa780961673a2df352e84a03d6a0b9c6e760
MD5 20d667feecc96c6dc415060b2aa9bdda
BLAKE2b-256 c7308161af7181fad53323bc12a32cdb38eb52fd717e47668fdec9d51e4c0b87

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page