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():
auth = OAuth2('test/app.json', 'test/user.json')
spreadsheet = Spreadsheet(auth, '1arnulJxyi-I6LEeCPpEy6XE5V87UF54dUAo9F8fM5rw')
page = await spreadsheet.page('Sheet 1')
print(page.link())
# https://docs.google.com/spreadsheets/d/1arnulJxyi-I6LEeCPpEy6XE5V87UF54dUAo9F8fM5rw/edit#gid=0
# 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(first_row)
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([21, 'u'])
await page.append_dict({'Foo': 22, 'Bar': 'v'})
await page.extend([[23, 'w'], [24, 'x']])
await page.extend_dicts([{'Foo': 25, 'Bar': 'y'}, {'Foo': 26, 'Bar': 'z'}])
# TODO: consider not using slices to simplify
# await sheet.delete(slice(-2, None))
await page.delete_range('A6:B11')
# 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: {await spreadsheet.tz()})")
# batch edits
async with page.batch() as batch:
batch.set_range("C2:D3", [[0, 1], [2, 3]])
asyncio.run(main())
Example CLI usage for getting authorized:
# WINDOWS
py -m SlySheets grant
# MacOS or Linux
python3 -m SlySheets grant
Granting credentials requires a Google Cloud Console account and JSON file. Please see https://docs.dunkyl.net/SlyAPI-Python/tutorial/oauth2.html for more information.
Metadata
Release files for SlySheets 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| SlySheets-0.2.3.tar.gz | 10.4 kB | Without provenance | Details for SlySheets-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| SlySheets-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for SlySheets-0.2.3-py3-none-any.whl |
Total release size: 19.5 kB
Release files / SlySheets-0.2.3.tar.gz
| Download URL | SlySheets-0.2.3.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbe62afdf8dcdaf37c8cd6b03cc3b1738b04f907367d735bee1bac57247d49ce
|
|
BLAKE2b-256 checksum How to use checksums |
5163d580dde08f0a48f035188f978b482d4964decd1f1dc10060c0b315229d4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.0
|
Release files / SlySheets-0.2.3-py3-none-any.whl
| Download URL | SlySheets-0.2.3-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
efe550f9d5382c4129ef6d37e5bb5c6678010c80f0778bcfe1d93960dc72e916
|
|
BLAKE2b-256 checksum How to use checksums |
16e01d710566d0e454c683fedeef73c3bdf713c719cd88459bc3e59b4b1e4de6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.0
|
Security for SlySheets 0.2.3
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.