pandasheets
pandasheets is a convenient wrapper around gspread that simplifies common operations such as downloading, uploading, and appending, when working with Google Sheets using pandas.
Getting Started
To use pandasheets, you need to set up a Google Cloud service account credential that grants your code access to manage spreadsheets. Below are the steps to create and configure these credentials:
1. Enable API access for your project
- Go to the Google Cloud Console.
- From the left-hand navigation menu, select APIs & Services.
- Click Enable APIs & Services, then Create project if you don’t already have one.
- Provide a Project name and Location, then click Create.
2. Create a Service Account Credential
- Under APIs & Services, click Credentials.
- Select Create credentials and choose Service account.
- Fill out the required fields (e.g., name, description).
- Copy the generated email address (it ends with
iam.gserviceaccount.com, e.g.,myserviceaccount@my-awesome-project.iam.gserviceaccount.com). - Click Create and continue.
- Assign a suitable Role for the service account.
- Finalize the creation process.
3. Generate the JSON key
- On the Service Accounts page, locate the service account you just created.
- Click on it to view the details.
- In the top menu, select Keys.
- Click Add key > Create new key > JSON > Create.
- A JSON file will be downloaded. Store it in a secure location.
4. Enable the Google Sheets API
- Return to APIs & Services in the Google Cloud Console.
- Click Enable APIs and services.
- Search for and select Google Sheets API.
- Click Enable.
5. Enable the Google Drive API
Repeat the process from Step 4 to enable the Google Drive API.
6. Share your spreadsheet
Finally, open the Google Sheet you want to access and click Share. Enter the service account email you copied in Step 2, and grant appropriate permissions (e.g., Editor). Click Done.
Important: Make sure the service account email has permission to access the spreadsheet and that both the Google Sheets API and the Google Drive API are enabled in your project.
Installation
pip install pandasheets
Usage
Instantiate once with the path to your JSON key
import pandasheets as ps
PS = ps.pandasheets(credential="path/to/credential.json")
Downloading a sheet from Google Sheets into a DataFrame
# Define the sheet name, spreadsheet name
sheet = "mySheet" # sheet to be downloaded and loaded as a DataFrame
spreadsheet = "mySpreadsheet" # Name of the spreadsheet containing the sheet
# Download the sheet and load it as a DataFrame
df = PS.get_sheet_to_dataframe(
sheet=sheet,
spreadsheet=spreadsheet,
)
Uploading a DataFrame to a new sheet
# Define your DataFrame, target sheet, spreadsheet name, and credential file
df = myDf # DataFrame to be uploaded
sheet = "mySheet" # Target sheet name for the upload
spreadsheet = "mySpreadsheet" # Name of the spreadsheet where the sheet will be created
PS.upload_dataframe_to_spreadsheet(
df=df,
sheet=sheet,
spreadsheet=spreadsheet,
)
By default, the DataFrame will be uploaded formatted as:
- Bold header
- All cells in columns A to Z are set to clip text wrapping
- The first row is frozen to keep the headers visible during scrolling.
If you wish to avoid the default formatting, call the function with the formatting parameter set to False:
PS.upload_dataframe_to_spreadsheet(
df=df,
sheet=sheet,
spreadsheet=spreadsheet,
formatting=False
)
By default, if a sheet with the same name already exists in the specified spreadsheet, a ValueError will be raised, as a new sheet will not be created. If you intend to overwrite the content of an existing sheet, set the parameter overwrite to True
PS.upload_dataframe_to_spreadsheet(
df=df,
sheet=sheet,
spreadsheet=spreadsheet,
formatting=False,
overwrite=True
)
Important: All the content of the existing sheet will be overwritten if
overwrite=True. If you only intend to append new values, useappend_dataframe_to_sheetas shown below.
Appending a DataFrame to an existing sheet
# Create a sample DataFrame to be appended
df_to_append = pd.DataFrame({
"column_A": ["A1", "A2", "A3"],
"column_B": ["B1", "B2", "B3"],
})
sheet = "mySheet" # Sheet name to which the data will be appended
spreadsheet = "mySpreadsheet" # Spreadsheet name where the sheet exists
PS.append_dataframe_to_sheet(
df=df_to_append,
sheet=sheet,
spreadsheet=spreadsheet,
)
Important: Only values for existing columns in the sheet are appended. Missing values in the DataFrame (present in the sheet) are set as empty strings. Duplicate values are not appended by default.
If duplicate values are acceptable and you would like to append them, set the duplicates parameter to True:
PS.append_dataframe_to_sheet(
df=df,
sheet=sheet,
spreadsheet=spreadsheet,
duplicates=True
)
Metadata
Release files for pandasheets 0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pandasheets-0.4.tar.gz | 45.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pandasheets-0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 76.5 kB
Release files / pandasheets-0.4.tar.gz
| Download URL | pandasheets-0.4.tar.gz |
|---|---|
| Size | 45.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a918a40c5f7cd25ba34fb30f3fd7f29ece1dd3a35893051a092a0cbb4374ce53
|
|
BLAKE2b-256 checksum How to use checksums |
0877b2a0fe71a648540921a06d6a534e8af407c00b270608cc66c6127ca49c74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 19, 2025.
Transparency logRelease files / pandasheets-0.4-py3-none-any.whl
| Download URL | pandasheets-0.4-py3-none-any.whl |
|---|---|
| Size | 31.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9458037c32be9a38500417190f25c942d97397cf92ef948ed1d25b7ad6bee69b
|
|
BLAKE2b-256 checksum How to use checksums |
ef4617a1690efcd9f96fb2aafeffc6189231f788c02de804ca05301eaf7ad5a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 19, 2025.
Transparency log