Skip to main content

A simple Python wrapper for the Google Spreadsheets API

Project description

A simple Python wrapper for the Google Spreadsheeta API.

Features

  • An object oriented interface for Worksheets

  • Supports List Feed view of spreadsheet rows, represented as dictionaries

  • Compatible with Google App Engine

Requirements

Before you get started, make sure you have:

Usage

List Spreadsheets and Worksheets:

>>> from google_spreadsheet.api import SpreadsheetAPI
>>> api = SpreadsheetAPI(GOOGLE_SPREADSHEET_USER, GOOGLE_SPREADSHEET_PASSWORD, GOOGLE_SPREADSHEET_SOURCE)
>>> spreadsheets = api.list_spreadsheets()
>>> spreadsheets
[('MyFirstSpreadsheet', 'tkZQWzwHEjKTWFFCAgw'), ('MySecondSpreadsheet', 't5I-ZPGdXjTrjMefHcg'), ('MyThirdSpreadsheet', 't0heCWhzCmm9Y-GTTM_Q')]
>>> worksheets = api.list_worksheets(spreadsheets[0][1])
>>> worksheets
[('MyFirstWorksheet', 'od7'), ('MySecondWorksheet', 'od6'), ('MyThirdWorksheet', 'od4')]

Please note that in order to work with a Google Spreadsheet it must be accessible to the user who’s login credentials are provided. The GOOGLE_SPREADSHEET_SOURCE argument is used by Google to identify your application and track API calls.

Working with a Worksheet:

>>> sheet = spreadsheet.get_worksheet('tkZQWzwHEjKTWFFCAgw', 'od7')
>>> rows = sheet.get_rows()
>>> len(rows)
18
>>> row_to_update = rows[0]
>>> row_to_update['name'] = 'New Name'
>>> sheet.update_row(0, row_to_update)
{'name': 'New Name'...}
>>> row_to_insert = rows[0]
>>> row_to_insert['name'] = 'Another Name'
>>> sheet.insert_row(row_to_insert)
{'name': 'Another Name'...}
>>> sheet.delete_row(18)
>>> sheet.delete_all_rows()
Advanced Queries:
>>> sheet = spreadsheet.get_worksheet('tkZQWzwHEjKTWFFCAgw', 'od7')
>>> rows = sheet.get_rows(query="age > 25 and height < 175")
Sort:
>>> sheet = spreadsheet.get_worksheet('tkZQWzwHEjKTWFFCAgw', 'od7')
>>> rows = sheet.get_rows(order_by='column:age', reverse='true')

That’s it.

For more information about these calls, please consult the [Google Spreadsheets API Developer Guide](https://developers.google.com/google-apps/spreadsheets/).

Tests

To run the test suite please follow these steps:

  • Make sure [Nose](http://readthedocs.org/docs/nose/en/latest/) is installed: (pip install nose)

  • Create a local file named: test_settings.py with the following variables set to the relevant values: GOOGLE_SPREADSHEET_USER, GOOGLE_SPREADSHEET_PASSWORD, GOOGLE_SPREADSHEET_SOURCE, GOOGLE_SPREADSHEET_KEY, GOOGLE_WORKSHEET_KEY, ‘COLUMN_NAME’, ‘COLUMN_UNIQUE_VALUE’

  • Run nosetests

License

Copyright &copy; 2012 Yoav Aviram

See LICENSE for details.

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

python-google-spreadsheet-1.0.3.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file python-google-spreadsheet-1.0.3.tar.gz.

File metadata

File hashes

Hashes for python-google-spreadsheet-1.0.3.tar.gz
Algorithm Hash digest
SHA256 ed7e55529eb0d7e9f7b8dafa2b87e74a0f3e73fa1d149f0a53405c24e7544a8d
MD5 3c563f36181deacdf053ec6a864dc1bc
BLAKE2b-256 72a4100e526e63f2184ea99d0716cb7b53c648a1d0e9aaddefddb9e98efccca9

See more details on using hashes here.

Supported by

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