Friday, May 31, 2013

Working With Google Spreadsheets Data Directly

On Wednesday I talked about assigning numbers to my princess-and-dragon story.  I have all my data in an easily parsable format in a Google Spreadsheet.  I decided to use Python to do my story-related computations because of the fast start-up time and the existence of the Google Data Python Library.

Things started well enough thanks to a decent quick start guide, even though I've only used Python a few times before.  I was able to connect to my spreadsheet without issue and start working with the spreadsheet's feed.

But from there things got... complicated.  The quick start guide didn't cover what I needed to do, and I kept getting referred to the spreadsheets API that made mention of other languages, but not Python.  This isn't the first time I've found documentation by Google to be lacking in some way.  I could probably figure things out eventually (perhaps by looking at the source code), but I didn't really want to spend that much time on getting the data - I would rather spend time processing it!

Luckily, @ArcTanSusan and @sharonw gave me a great suggestion on Twitter: gspread.  It was made for Python specifically, has good documentation, and offers much simpler code for doing what I needed to do.  Sign me up!

Making the switch saved me a bunch of time in the end.  The moral of the story: use gspread to work with Google Spreadsheets in Python, and search for alternatives before just using Google's stuff.


Post a Comment

Comments are moderated - please be patient while I approve yours.