Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yoavaviram/python-google-spreadsheet
A simple Python wrapper for the Google Spreadsheet API
https://github.com/yoavaviram/python-google-spreadsheet
Last synced: 3 days ago
JSON representation
A simple Python wrapper for the Google Spreadsheet API
- Host: GitHub
- URL: https://github.com/yoavaviram/python-google-spreadsheet
- Owner: yoavaviram
- License: other
- Created: 2012-04-11T15:53:59.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-10-05T09:57:27.000Z (about 12 years ago)
- Last Synced: 2024-10-08T00:41:23.713Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 136 KB
- Stars: 63
- Watchers: 7
- Forks: 18
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Google Spreadsheets API
========================
A simple Python wrapper for the Google Spreadsheeta API.
[![Build Status](https://secure.travis-ci.org/yoavaviram/python-google-spreadsheet.png?branch=master)](http://travis-ci.org/yoavaviram/python-google-spreadsheet)Features
--------* An object oriented interface for Worksheets
* Supports List Feed view of spreadsheet rows, represented as dictionaries
* Compatible with Google App EngineRequirements
--------------
Before you get started, make sure you have:* Installed [Gdata](http://code.google.com/p/gdata-python-client/) (pip install gdata)
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(row_to_update)
{'name': 'New Name'...}
>>> row_to_insert = rows[0]
>>> row_to_insert['name'] = 'Another Name'
>>> row = sheet.insert_row(row_to_insert)
{'name': 'Another Name'...}
>>> sheet.delete_row(row)
>>> sheet.delete_all_rows()Advanced Queries:
>>> sheet = spreadsheet.get_worksheet('tkZQWzwHEjKTWFFCAgw', 'od7')
>>> rows = sheet.get_rows(query='name = "Joe" and height < 175')Or filter in memory:
>>> sheet = spreadsheet.get_worksheet('tkZQWzwHEjKTWFFCAgw', 'od7')
>>> filtered_rows = sheet.get_rows(
filter_func=lambda row: row['status'] == "READY")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 © 2012 Yoav Aviram
See LICENSE for details.