GSpreadPlus - Google Spreadsheets GSpreadPlus
Made on top of the orginal gspread Python API Wrapper, this wrapper (wrapper of a wrapper) targets at specific use cases such as returning row after finding column for a value. You'll get it if you use it.
Installation
Using PIP
Windows - Command Prompt:
python -m pip install GSpreadPlus
OR
Linux/MacOs - Terminal
python3 -m pip install GSpreadPlus
Done!!!
Project Status
AlphaBeta- Open Source
Tutorial
1. Import & Initializing
Import:
from GSpreadPlus import Spreadclient
Intialising:
client = Spreadclient('credentials.json')
OR
from json import loads
creds = loads('credentials.json')
client = Spreadclient(creds)
2. Connecting to Document/Sheet
To connect to the document, you need either one of the following Identifiers:
- Document Name
- Document Unique ID (Can be found in URL)
- Document URL
Connecting to Document:
client.connect_document('Banana Sales')
# OR
client.connect_document('4n5Dk5nfSxW1kNKG6vjZOAulDKgMb7JgcKEVlJb4mMpY')
# OR
client.connect_document('https://docs.google.com/spreadsheets/d/4n5Dk5nfSxW1kNKG6vjZOAulDKgMb7JgcKEVlJb4mMpY')
Connecting to Worksheet:
- By Name
- By Index (Pythonic)
client.connect_sheet('Monkey Employees')
# OR
client.connect_sheet(0)
Extra Attributes for Databases:
- Orientation -
orientation- If you are treating the spreadsheet like a database, you can set the
orientationto either'vertical'(default) or'horizontal' - This will automatically get the headers depending on the orientation
- If the data is propagating
vertically, that would be the orientation ;
- If you are treating the spreadsheet like a database, you can set the
- Headers Depth -
headers_depth- If your databases have headers that are not starting from the first row/column you can change the depth
- For example if your headers are at row 3, the headers depth would be
3
client.connect_sheet(
'Monkey Employees',
orientation='horizontal',
headers_depth=3
)
3. Reading Data
Accessing the listed and headers attribute will gain access to their respective properties.
listed returns a list of list, where each list represents a row and each element in the inner list represents a cell
headers returns the headers based on the orientation
Refreshing:
Refreshing the data will send a request to the server for the new data and will push new local commits(changes).
Do note that refreshing will overwrite listed and it will overwrite the live spreadsheet regardless of its state.
In essence, we are assuming the live spreadsheet data doesn't get changed between the last fetched data and that instance.
client.refresh_sheet()
data = client.listed
print(f"There are {len(data)} rows in this sheet")
headers = client.headers
print(f"This spreadsheets' headers: {headers}")
Do note that
client.refresh_sheet()should be used sparingly in order to reduce requests sent to the server and ultimately avoidingTOO_MANY_REQUESTS
4. Querying Data
Since this package is for sheets that work/act as databases, the following functions exist to assist in such tasks
Included Refreshing
For ALL query functions, and optional parameter
refresh=Falseis available.When set to
True,self.refresh_sheet()will be invoked before executing the relevant function
A. Get Row by Column
get_row_by_column(self, value: Union[str, int], column: Union[str, int] = 0, refresh: bool = False)->list[Any]
Parameters
value: Union[str, int]- This is the value that will be searched.
- Returns a list of element for the first row that
<column>matchesvalue(case-sensitive)
column: Union[str, int]- This is the column that
valuewill be searched in columncan be column name (e.g.'A') or index (Pythonic, e.g.0)
- This is the column that
B. Get Dimension by Header Name
get_dime_by_header(self, value: Union[str,int], header: Union[str, int], refresh: bool = False)->list[Any]
Parameters
value: Union[str, int]- This is the value that will be searched.
- Returns a list of element for the first row/column that
<header attribute>matchesvalue(case-sensitive)
header: Union[str, int]- This is the
headerfor the column thatvaluewill be searched in headeris case-sensitive
- This is the
C. Get Rows by Function
get_rows_by_func(self, function: Callable, refresh: bool = False)->list[Any]
Parameters
function: Callablefunctionshould accept 1 parameter which is therow(i.e. list of cells in each row)- Should return a
booleanvalue
matches = client.get_rows_by_func(
lambda r:'pizza' in r[
client.get_header_index('Fav Food')
].lower(),
refresh = True
)
D. Commit/Add New Row
commit_new_row(self, values: Union[list,dict], offset:int=0, refresh=True)->list[gspread.models.Cell]
Parameters
values: Union[list,dict]- Add new row of values based on dict keys or just by listical order
- If
refresh=False, the update will NOT be LIVE untilrefresh_sheet()is called again.
Returns list of Cells that have been added to
self.commits
Metadata
Release files for GSpreadPlus 0.5.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 |
|---|---|---|---|---|
| gspreadplus-0.5.3.tar.gz | 11.6 kB | Without provenance | Details for gspreadplus-0.5.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gspreadplus-0.5.3-py3-none-any.whl | Python 3 | none | any | Details for gspreadplus-0.5.3-py3-none-any.whl |
Total release size: 21.2 kB
Release files / gspreadplus-0.5.3.tar.gz
| Download URL | gspreadplus-0.5.3.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ced56305b918a7f9ba590cd449aff2ffd433b9b0212bb448caecdc18e01c51a2
|
|
BLAKE2b-256 checksum How to use checksums |
7f744c83249c8ac9e5ee247127ec3e9b07ba1b9714cdbe3649f0fb4d466b5fad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / gspreadplus-0.5.3-py3-none-any.whl
| Download URL | gspreadplus-0.5.3-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a148adf48b82abc39ba1e6b0c2c4b53c83afbfca28221949e180442b37ea21d9
|
|
BLAKE2b-256 checksum How to use checksums |
d26310673ab512535d053f18ee27eceb947aa134bc30e9fb0f7a2c7e3d36e3b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for GSpreadPlus 0.5.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.