Skip to main content

Export tables to Google Spreadsheets.

Project description

https://travis-ci.org/maybelinot/df2gspread.png https://coveralls.io/repos/maybelinot/df2gspread/badge.svg

INSTALLATION

Example install, using VirtualEnv:

# install/use python virtual environment
virtualenv ~/virtenv_scratch --no-site-packages

# activate the virtual environment
source ~/virtenv_scratch/bin/activate

# upgrade pip in the new virtenv
pip install -U pip setuptools

# install this package in DEVELOPMENT mode
# python setup.py develop

# simply install
# python setup.py install

# or install via pip
pip install df2gspread

ACCESS 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 file to ~/.gdrive_private.

  • Then, the first time you run it your browser window will open a google authorization request page. Approve authorization and then the credentials will work as expected.

USAGE

Run df2gspread like:

from df2gspread import df2gspread as d2g
import pandas as pd
d = [pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
    pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])]
df = pd.DataFrame(d)

# use full path to spreadsheet file
spreadsheet = '/some/folder/New Spreadsheet'
# or spreadsheet file id
# spreadsheet = '1cIOgi90...'

wks_name = 'New Sheet'

d2g.upload(df, spreadsheet, wks_name)
# if spreadsheet already exists, all data of provided worksheet(or first as default)
# will be replaced with data of given DataFrame, make sure that this is what you need!

Run gspread2df like:

from df2gspread import gspread2df as g2d

# use full path to spreadsheet file
spreadsheet = '/some/folder/New Spreadsheet'
# or spreadsheet file id
# spreadsheet = '1cIOgi90...'
wks_name = 'New Sheet'

df = g2d.download(spreadsheet, wks_name, col_names = True, row_names = True)

DEVELOPMENT

Install the supplied githooks; eg:

ln -s ~/repos/df2gspread/_githooks/commit-msg ~/repos/df2gspread/.git/hooks/commit-msg
ln -s ~/repos/df2gspread/_githooks/pre-commit ~/repos/df2gspread/.git/hooks/pre-commit

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

df2gspread-0.0.6.tar.gz (9.0 kB view details)

Uploaded Source

File details

Details for the file df2gspread-0.0.6.tar.gz.

File metadata

  • Download URL: df2gspread-0.0.6.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for df2gspread-0.0.6.tar.gz
Algorithm Hash digest
SHA256 9ac3a1f262c88b4f52574415b973b115570115d89726eba58a7559f21d1a8bac
MD5 12029204bb8e634747ee83a27eca571f
BLAKE2b-256 f1d9b5fc4cef5f1b663585832eea2a6c20417415b1c0e55a2130c724549fa157

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