Skip to main content

No-boilerplate, async and typed Google Sheets access.

Project description

sly logo SlySheets for Python

🚧 This library is an early work in progress! Breaking changes may be frequent.

🐍 For Python 3.10+

No-boilerplate, async and typed Google Sheets access. 😋

pip install slysheets

This library does not have full coverage. Currently, the following topics are supported:

  • Editing sheet cells
  • Reading sheet metadata

You can use SlyAPI to directly grant user tokens using the command line, covering the whole OAuth 2 user grant process after getting client credentials from Google.


Example usage:

import asyncio
from SlySheets import *

async def main():

    spreadsheet = await Spreadsheet('test/app.json', 'test/user.json', '1arnulJxyi-I6LEeCPpEy6XE5V87UF54dUAo9F8fM5rw')
    page = spreadsheet.page('Sheet 1')

    # A1 notation
    a1 = await page.cell('A1')
    print(F"Cell A1: {a1}") # Cell A1: Foo

    # zero-indexed rows
    first_row = await page.row(0)
    print(F" | {first_row[0]:6} | {first_row[1]:6} |") # | Foo     | Bar     |

    # header-indexed columns
    foos = await page.column_named('Foo')
    print(F"Foos: {foos}") # Foos: [1, 2, 3, 26]

    # zero-indexed columns
    foos_2 = await page.column(0)
    assert foos == foos_2

    for row in await page.rows_dicts(1, 4):
        # index result by header
        print(F" | {row['Foo']:6} | {row['Bar']:6} |") # |      1 | a     | etc...

    # append and extend, of course
    await page.append([0, 'u'])
    await page.append_dict({'Foo': 1, 'Bar': 'v'})

    await page.extend([[3, 'w'], [4, 'x']])
    await page.extend_dicts([{'Foo': 5, 'Bar': 'y'}, {'Foo': 6, 'Bar': 'z'}])

    # TODO: consider not using slices to simplify    
    # await sheet.delete(slice(-2, None))
    await page.delete_range('A6:B7')

    # use spreadsheet object to update a specific page with A1 notation
    await spreadsheet.set_cell("'Sheet 1'!E3", 'Hello World!')

    # dates
    today = await page.date_at_cell('D5') # =TODAY()
    assert isinstance(today, datetime)
    print(F"It is now {today.isoformat()} (timezone: {spreadsheet.tz})")


    # batch edits
    async with sheet.batch() as batch:
        batch.set_range("C2:D3", [[0, 1], [2, 3]])

asyncio.run(main())

Project details


Download files

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

Source Distribution

SlySheets-0.1.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

SlySheets-0.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file SlySheets-0.1.1.tar.gz.

File metadata

  • Download URL: SlySheets-0.1.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for SlySheets-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6ae94ad7609944b7357cc1209b86a8189e582dd950c89b934bd9016c64aec932
MD5 72988a49e33a0f48b0d0515f15ceb1a1
BLAKE2b-256 0e70d71ff4a267339a4ba5ca86e0583922603bf2d7aa28c80a39515d563c1d5b

See more details on using hashes here.

File details

Details for the file SlySheets-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: SlySheets-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for SlySheets-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5dc8be6d87228a8dc0e13b67e6b26d7e70830887e07372fb3ac668e8e7ca2682
MD5 d9059dca9468028498244fecd968e85a
BLAKE2b-256 fc99a283ff1f99e23f966e976a483ae99989882bb18011726685589b8605eb42

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