I'd like to be able to call a script, which will add a row to a Google Spreadsheet, and manage stuff like user login. For example,

 gdocs_addrow --id <doc-id> name="John Doe" age="31"

I know there are nice Python APIs but I want to work at an even higher level.

My use case is that I want to make a script that uploads unit test results to a shared document.


2 Answers 2


I wrote such a tool. It's written in python, but designed to be used from the command line. Have a look at logss. I've been using it to upload daily stats from a cron job.

Beware: I've not got great python installation skills, so running it is a little ad-hoc.


If you want a row for each unit test, and for the command to either add a row or update an existing row then you need to have a key column. I've written&used this python library for similar problems: http://sheetsync.readthedocs.org/en/latest/

Once you've installed it with:

pip install sheetsync

You could write a gdocs_addrow.py script like so:

import sys,sheetsync,argparse

def parse_cmd_line():
    parser = argparse.ArgumentParser()
    parser.add_argument("--id", metavar="GOOGLESHEET_KEY",required=True)
    parser.add_argument("--key", metavar="KEY_COLUMN_NAME",required=True)
    parser.add_argument("--sheet", metavar="WORKSHEET_NAME",default="Sheet1")
    parser.add_argument('fieldvals', metavar='FIELD=VALUE', nargs='+',
                       help="A list of FIELD=VALUE arguments")
    opts = parser.parse_args()
    opts.fieldvalue_dict = dict([fv.split("=") for fv in opts.fieldvals])
    if not opts.fieldvalue_dict.has_key(opts.key):
        print "'%s' specified as the key field, but not found in field=value list" %     opts.key
    opts.key_value = opts.fieldvalue_dict[opts.key]
    return opts

if __name__ == '__main__':
    opts = parse_cmd_line()
    target = sheetsync.Sheet(username="<YOUR_GOOGLE_USERNAME>", 

and use like this:

gdocs_addrow.py --id 1iZa...BqQ --key name name="Trevor B" age="31"
  • Can you explain what this does and how it helps? Jul 31, 2014 at 14:54
  • @AndrewLott hope that's clearer.
    – mbrenig
    Aug 1, 2014 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.