pygsheets

A simple, intutive library for google spreadsheets based on api v4 which gets most of your work done.

Features

  • Google spreadsheet api v4 support
  • Open, create, delete and share spreadsheets using _title_
  • Control permissions of spreadsheets.
  • Extract range, entire row or column values.
  • Set cell format, text format, coloe, write notes
  • NamedRanges Support
  • Do all the updates and push the changes in a batch

Small Example

Sample scenario : you want to share a numpy array with your remote friend

import pygsheets

gc = pygsheets.authorize()

# Open spreadsheet and then workseet
sh = gc.open('my new ssheet')
wks = sh.sheet1

# Update a cell with value (just to let him know values is updated ;) )
wks.update_cell('A1', "Hey yank this numpy array")

# update the sheet with array
wks.update_cells('A2', my_nparray.to_list())

# share the sheet with your friend
sh.share("myFriend@gmail.com")

Sample scenario: you want to store students name and their heights

## import and open the sheet as given above

header = wks.cell('A1')
header.value = 'Names'
header.text_format['bold'] = True # make the header bold
header.update()

# or achive the same in oneliner
wks.cell('B1').set_text_format('bold', True).value = 'heights'

# set the names
wks.update_cells('A2:A5',[['name1'],['name2'],['name3'],['name4']])

# set the heights
heights = wks.range('B2:B5')  # get the range
heights.name = "heights"  # name the range
heights.update_values([[50],[60],[67],[66]]) # update the vales
wks.update_cell('B6','=average(heights)') # set get the avg value

Installation

pip install https://github.com/nithinmurali/pygsheets/archive/master.zip (recent)
pip install pygsheets (stable)

Overview

There are mainly 4 models - spreadsheet, worksheet, cell, DataRange they are defined in their respectivr files. The communication with google api is implimented in client.py. The client.py also impliments the autorization functions.

Authors and License

The pygsheets package is written by Nithin Murali and is inspried by gspread. It’s MIT licensed and freely available.

Feel free to improve this package and send a pull request to GitHub.

Contents:

Indices and tables