Friday, February 13, 2015

Google Spreadsheet Python

Just found an awesome python module this morning called gspread. The module allows you to work with Google Spreadsheets. You can read data, write data, work with worksheets, and all kinds of other functions. You can find out more about the module on GitHub

I went from install, to sample code, to hacking spreadsheets in about 35 seconds. It was so easy.

Easy_Install the Module

  1. Open up a console and browse to my Python\scripts folder
  2. Run easy_install (setup instructions for easy_Install) like so: easy_install gspread
  3. Easy Install does all the heavy lifting.

Create a Spreadsheet

Create a spreadsheet in Google Drive and call it whatever you want. Remember the name because you will need it for your sample script.

Sample Script

You will see some sample scripts on the GitHub project page. Here is my script.

It really is that simple. You just setup your username and password. The module will then will convert that to an Oauth session for you to authenticate to Google securely.  We open the spreadsheet with the"Pythontest").sheet1 command.

You can see the update command is commented out: wks.update_acell('B2',"some data here"). You can fetch a range of cells and print out the values. You can retrieve whole columns or rows.

This module is awesome and so easy to use.


Post a Comment