Wrapper for gspread
Project description
Gspread2
A wrapper around gspread for easier usage. Intended to provide features and syntax similar to OpenPyXL.
DISCLAIMER: This library is still under development!
Features
- Cell Formatting such as Fonts, Colors and Borders
- OpenPyXL functions such as
iter_rows()
anditer_cols()
- Values are automatically applied to the sheet when updated
Roadmap/TODO
- Documentation (WIP)
- Formulas
- Filters and Pivot Tables
Installation
Requirements:
- Python3.6+
Install via Pip
$ pip install gspread2
Basic Usage
Getting Started
Create API credentials
Before using this library, you must log into Google Developers page and set up a Service Account, allowing read/write access to your Google Sheets.
-
Head to Google Developers Console and create a new project (or select the one you have.)
-
Navigate to "API & Services", "Credentials".
-
Click on "CREATE CREDENTIALS", "Service account" and follow through the prompts. On the last page, create a JSON key and save it locally. You will need to import this into the library to authenticate to the API.
-
Once you hit "Done", you will see the email address under "Service Accounts", make note of that email.
-
On your Google Sheet, hit "Share" and add the email above.
-
You should now have the credentials and permissions to view and edit your Google Sheet.
Load Workbook
To access a Workbook, you'll need the Google Sheet URL and the credentials file as shown above. The following code example will return a Workbook object:
import gspread2
URL = 'https://docs.google.com/spreadsheets/d/spreadsheetID'
CREDENTIALS = 'path/to/json.file'
workbook = gspread2.load_workbook(URL, CREDENTIALS)
You can also import the Workbook class and initialise it with the same parameters:
from gspread2.models import Workbook
URL = 'https://docs.google.com/spreadsheets/d/spreadsheetID'
CREDENTIALS = 'path/to/json.file'
workbook = Workbook(URL, CREDENTIALS)
Load Worksheet
Once you have a Workbook loaded, you can access worksheets in a number of ways:
workbook = gspread2.load_workbook(URL, CREDENTIALS)
worksheet = workbook['Sheet 1']
OR
workbook = gspread2.load_workbook(URL, CREDENTIALS)
worksheet = workbook.get_sheet_by_name('Sheet 1')
To get the first sheet (usually the active one):
workbook = gspread2.load_workbook(URL, CREDENTIALS)
worksheet = workbook.active
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.