Skip to main content

A package to easily open an instance of a Google spreadsheet and interact with worksheets through Pandas DataFrames.

Project description

PyPI version

author: Diego Fernandez

Links:

Overview

A package to easily open an instance of a Google spreadsheet and interact with worksheets through Pandas DataFrames.

Some key goals/features:

  • Nicely handle headers and indexes.

  • Run on Jupyter, headless server, and/or scripts

  • Allow storing different user credentials

  • Automatically handle token refreshes

Installation / Usage

To install use pip:

$ pip install gspread-pandas

Or clone the repo:

$ git clone https://github.com/aiguofer/gspread-pandas.git
$ python setup.py install

Before using, you will need to download Google client credentials for your app.

Client Credentials

To allow a script to use Google Drive API we need to authenticate our self towards Google. To do so, we need to create a project, describing the tool and generate credentials. Please use your web browser and go to Google console and :

  • Choose Create Project in popup menu on the top.

  • A dialog box appears, so give your project a name and click on Create button.

  • On the left-side menu click on API Manager.

  • A table of available APIs is shown. Switch Drive API and click on Enable API button. Other APIs might be switched off, for our purpose.

  • On the left-side menu click on Credentials.

  • In section OAuth consent screen select your email address and give your product a name. Then click on Save button.

  • In section Credentials click on Add credentials and switch OAuth 2.0 client ID.

  • A dialog box Create Cliend ID appears. Select Application type item as Other.

  • Click on Create button.

  • Click on Download JSON icon on the right side of created OAuth 2.0 client IDs and store the downloaded file on your file system. Please be aware, the file contains your private credentials, so take care of the file in the same way you care of your private SSH key; i.e. move downloaded JSON to ~/.google/google_secret.json (or you can configure the directory and file name by directly calling gspread_pandas.conf.get_config

Thanks to similar project df2gspread for this great description of how to get the client credentials.

User Credentials

Once you have your client credentials, you can have multiple user credentials stored in the same machine. This can be useful when you have a shared server (for example with a Jupyter notebook server) with multiple people that may want to use the library. The first parameter to Spread must be the key identifying a user’s credentials. The first time this is called for a specific key, you will have to authenticate through a text based OAuth prompt; this makes it possible to run on a headless server through ssh or through a Jupyter notebook. After this, the credentials for that user will be stored (by default in ~/.google/creds)and the tokens will be refreshed automatically any time the tool is used.

Users will only be able to interact with Spreadsheets that they have access to.

Contributing

$ git clone https://github.com/aiguofer/gspread-pandas.git && cd gspread-pandas
$ pip install -e ".[dev]"

TBD

Example

from __future__ import print_function
import pandas as pd
from gspread_pandas import Spread

file_name = "http://www.ats.ucla.edu/stat/data/binary.csv"
df = pd.read_csv(file_name)

# 'Example Spreadsheet' needs to already exist and your user must have access to it
spread = Spread('example_user', 'Example Spreadsheet')
# This will ask to authenticate if you haven't done so before for 'example_user'

# Display available worksheets
spread.sheets

# Save DataFrame to worksheet 'New Test Sheet', create it first if it doesn't exist
spread.df_to_sheet(df, index=False, sheet='New Test Sheet', start='A2', replace=True)
spread.update_cells((1,1), (1,2), ['Created by:', spread.email])
print(spread)
# <gspread_pandas.client.Spread - User: '<example_user>@gmail.com', Spread: 'Example Spreadsheet', Sheet: 'New Test Sheet'>

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

gspread-pandas-0.10.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gspread_pandas-0.10.0-py3.8.egg (39.1 kB view details)

Uploaded Egg

gspread_pandas-0.10.0-py3.6.egg (20.9 kB view details)

Uploaded Egg

gspread_pandas-0.10.0-py3.5.egg (17.8 kB view details)

Uploaded Egg

gspread_pandas-0.10.0-py2.py3-none-any.whl (13.7 kB view details)

Uploaded Python 2Python 3

gspread_pandas-0.10.0-py2.7.egg (17.5 kB view details)

Uploaded Egg

File details

Details for the file gspread-pandas-0.10.0.tar.gz.

File metadata

File hashes

Hashes for gspread-pandas-0.10.0.tar.gz
Algorithm Hash digest
SHA256 b365a56c17945d2cfe719570b5102ac78c57a7fa49503991bb1592969dd03680
MD5 dd5864d59f70ce28927455b599e232de
BLAKE2b-256 f366c86cbe1ae9adc0dee998201e1490aec628a9d6082c65472027ff7922fe2e

See more details on using hashes here.

File details

Details for the file gspread_pandas-0.10.0-py3.8.egg.

File metadata

  • Download URL: gspread_pandas-0.10.0-py3.8.egg
  • Upload date:
  • Size: 39.1 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.8

File hashes

Hashes for gspread_pandas-0.10.0-py3.8.egg
Algorithm Hash digest
SHA256 ba0f7aac6bbd1fcb0d1cc412797c4ad4068ed0c87f17f7bc1cb33c3885cd7828
MD5 3e5eb2d497ae0ad1f2e1b40900b88d81
BLAKE2b-256 69b134626f5b23b095944d157370facc3c78e21fba79f807e37fd327a484ef76

See more details on using hashes here.

File details

Details for the file gspread_pandas-0.10.0-py3.6.egg.

File metadata

File hashes

Hashes for gspread_pandas-0.10.0-py3.6.egg
Algorithm Hash digest
SHA256 151c2e6004f36e295bab71d390df807dbc3d0b67b49238bd0edd2f1c31645212
MD5 619d72fba42abca95e89333bbe1b77d3
BLAKE2b-256 ab8429cdb40bb34e9031c3074170fa959fa147689c8f5f5922bbbc65f3e95c10

See more details on using hashes here.

File details

Details for the file gspread_pandas-0.10.0-py3.5.egg.

File metadata

File hashes

Hashes for gspread_pandas-0.10.0-py3.5.egg
Algorithm Hash digest
SHA256 009c99692dc5dc43a839b1736084c5d112b674a98f160716f3120b61c61dde5a
MD5 355d267b4fa21ecd009dc459cb8feae0
BLAKE2b-256 71fad7cf3815402339358a6660dd188e106be7071e45c16a2169a361c6a30849

See more details on using hashes here.

File details

Details for the file gspread_pandas-0.10.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for gspread_pandas-0.10.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f9036d5ce0102e47a38fa583aaf5e44c39c6ffb0e1a8c060ca0d20b50f6dbc6e
MD5 2c0f97f1da0296e05dfa0c7ffba90286
BLAKE2b-256 bb1204f374d3dba430d5dec645ac328dd907b66aae3541e835e7d6598005ca9c

See more details on using hashes here.

File details

Details for the file gspread_pandas-0.10.0-py2.7.egg.

File metadata

File hashes

Hashes for gspread_pandas-0.10.0-py2.7.egg
Algorithm Hash digest
SHA256 65e890e1e44c41fa31592d07bce377a022e502aa08a8bdff94d841a399463957
MD5 7495bd365ba3533532c42c22bfd4b4f7
BLAKE2b-256 16a1c960be67f19210351d1ad4eeb1648f12c34f7720b53ad3fb462a09829f20

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page