Skip to main content

Sheetfu

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

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

You can also create your SpreadsheetApp object with environment variables instead of the secrets.json file. You can refer to the authentication tutorial for more info.

Please read 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.

Casting

An effort has been made to guide Sheetu as a Google Sheet ORM, where any values found in a spreadsheet are casted to a matching Python object. Since version 1.5.7, Sheetfu returns DATE and DATE_TIME as Python datetime object. Similarly, setting a cell with a datetime object will make the necessary parsing and casting to reflect those cells as DATE_TIME in the sheet.

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')

# Assuming the cells are in DATE or DATE_TIME format.
cells_with_dates = sheet.get_range_from_a1("A1:A2"))

print(cells_with_dates.get_values())
#   [
#       [datetime.datetime(2021, 11, 26, 16, 58, 37, 737940)],
#       [datetime.datetime(2021, 11, 26, 16, 58, 37, 737940)]
#   ]

This means we can introduce python datetime operation in our code very effectively.

from sheetfu import SpreadsheetApp
from datetime import datetime

sa = SpreadsheetApp('path/to/secret.json')
spreadsheet = sa.open_by_id('<insert spreadsheet id here>')
sheet = spreadsheet.get_sheet_by_name('Sheet1')

a1 = sheet.get_range_from_a1("A1")

# The following will set today's date in the
#cell in the right google sheet format
a1.set_value(datetime.today())

Contributing

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

Metadata

Release files for sheetfu 1.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sheetfu 1.6.1
File Size Uploaded Provenance
sheetfu-1.6.1.tar.gz 20.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sheetfu 1.6.1
File Interpreter ABI Platform
sheetfu-1.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 41.2 kB

Release files / sheetfu-1.6.1.tar.gz

Download URL sheetfu-1.6.1.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
507ffbba26af03240f8c7036fc0515b2da9ca4c8a2e1a32d94402f66b050e9eb
BLAKE2b-256 checksum
How to use checksums
2aff712e36188cc39ae289707946d6f0608b6957fac7b647915fab1e7406d3aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / sheetfu-1.6.1-py3-none-any.whl

Download URL sheetfu-1.6.1-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a93f9ddbaf78583b28b60d7299174ff3040448faf84b9114b6420d0afe88c81c
BLAKE2b-256 checksum
How to use checksums
3d9d3b1c37b396794a67251e1e3fc627ad183334956dc390b2d1efeebfb3300f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Security for sheetfu 1.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page