gsheetsplus
gsheetsplus is an extension over the gsheets library to provide added functionalities like plotting graphs between two axis.
Turn on the API, download an OAuth client ID as JSON file, and create a
Sheets object from it. Use its index access (__getitem__) to retrieve
SpreadSheet objects by their id, or use .get() with a sheet URL.
Iterate over the Sheets object for all spreadsheets, or fetch spreadsheets
by title with the .find() and .findall() methods.
SpreadSheet objects are collections of WorkSheets, which provide access to the
cell values via spreadsheet coordinates/slices (e.g. ws['A1']) and
zero-based cell position (e.g. ws.at(0, 1)).
Links
- GitHub: https://github.com/tanmaypandey7/gsheetsplus
- PyPI: https://pypi.org/project/gsheetsplus/
- Download: https://pypi.org/project/gsheetsplus/#files
Installation
This package runs under 3.8+, use pip to install:
pip install gsheetsplus
This will also install gsheets, matplotlib and their dependencies.
Quickstart
Log into the Google Developers Console with the Google account whose spreadsheets you want to access. Create (or select) a project and enable the Drive API and Sheets API (under Google Apps APIs).
Go to the Credentials for your project and create New credentials >
OAuth client ID > of type Other. In the list of your OAuth 2.0 client
IDs click Download JSON for the Client ID you just created. Save the
file as client_secrets.json in your home directory (user directory).
Another file, named storage.json in this example, will be created after
successful authorization to cache OAuth data.
On you first usage of gsheets with this file (holding the client secrets),
your webbrowser will be opened, asking you to log in with your Google account
to authorize this client read access to all its Google Drive files and Google
Sheets.
Create a sheets object:
>>> from gsheets import Sheets
>>> sheets = Sheets.from_files('~/client_secrets.json', '~/storage.json')
>>> sheets #doctest: +ELLIPSIS
<gsheets.api.Sheets object at 0x...>
Fetch a spreadsheet by id or url:
# id only
>>> sheet['1dR13B3Wi_KJGUJQ0BZa2frLAVxhZnbz0hpwCcWSvb20']
<SpreadSheet 1dR13...20 u'Spam'>
# id or url
>>> url = 'https://docs.google.com/spreadsheets/d/1dR13B3Wi_KJGUJQ0BZa2frLAVxhZnbz0hpwCcWSvb20'
>>> s = sheets.get(url)
>>> s
<SpreadSheet 1dR13...20 u'Spam'>
Access worksheets and their values:
# first worksheet with title
>>> s.find('Tabellenblatt2')
<WorkSheet 1747240182 u'Tabellenblatt2' (10x2)>
# worksheet by position, cell value by index
>>> s.sheets[0]['A1']
u'spam'
# worksheet by id, cell value by position
>>> s[1747240182].at(row=1, col=1)
1
Dump a worksheet to a CSV file:
>>> s.sheets[1].to_csv('Spam.csv', encoding='utf-8', dialect='excel')
Dump all worksheet to a CSV file (deriving filenames from spreadsheet and worksheet title):
>>> csv_name = lambda infos: '%(title)s - %(sheet)s.csv' % infos
>>> s.to_csv(make_filename=csv_name)
Load the worksheet data into a pandas DataFrame (requires pandas):
>>> s.find('Tabellenblatt2').to_frame(index_col='spam')
eggs
spam
spam eggs
...
WorkSheet.to_frame() passes its kwargs on to pandas.read_csv()
Plot graph between two axis(requires pandas):
>>> df = s.find("Sheet1").to_frame()
>>> sheets.plot(df, "offer_price", "average_sales", "graph")
>>> plt.show()
Detailed documentation for Gsheets can be found here.
See also
- gsheets Base library for gsheetsplus
- gsheets.py self-containd script to dump all worksheets of a Google Spreadsheet to CSV or convert any subsheet to a pandas DataFrame (Python 2 prototype for this library)
- gspread Google Spreadsheets Python API (more mature and featureful Python wrapper, currently using the XML-based legacy v3 API)
- example Jupyter notebook using gspread to fetch a sheet into a pandas DataFrame
- df2gspread Transfer data between Google Spreadsheets and Pandas (build upon gspread, currently Python 2 only, GPL)
- pygsheets Google Spreadsheets Python API v4 (v4 port of gspread providing further extensions)
- gspread-pandas Interact with Google Spreadsheet through Pandas DataFrames
- pgsheets Manipulate Google Sheets Using Pandas DataFrames (independent bidirectional transfer library, using the legacy v3 API, Python 3 only)
- PyDrive Google Drive API made easy (google-api-python-client wrapper for the Google Drive API, currently v2)
License
This package is distributed under the MIT license.
Metadata
Release files for gsheetsplus 0.3.5
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 |
|---|---|---|---|---|
| gsheetsplus-0.3.5.tar.gz | 4.5 kB | Without provenance | Details for gsheetsplus-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gsheetsplus-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for gsheetsplus-0.3.5-py3-none-any.whl |
Total release size: 10.0 kB
Release files / gsheetsplus-0.3.5.tar.gz
| Download URL | gsheetsplus-0.3.5.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
80e2bcfab3e9b576f450ba1fdfe34d8a13c2333244f3b3adb7b849a05262fb7e
|
|
BLAKE2b-256 checksum How to use checksums |
660a9dc50ab3093c966e89c709dc08731701c8b92255ba50dda838e999cfdd50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/50.3.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.2
|
Release files / gsheetsplus-0.3.5-py3-none-any.whl
| Download URL | gsheetsplus-0.3.5-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4dca3fb762d568a99699dde790eacc5e4fcf1fb378d043512435a87b6c65cb17
|
|
BLAKE2b-256 checksum How to use checksums |
6eac6f5d9820176305abe6e25be07e068c591e6ae606e36e9367413d594ba59d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/50.3.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.2
|
Security for gsheetsplus 0.3.5
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.