A lightweight logging utility for dumping structured data into Google Sheet.
Run python setup.py install
Set GDRIVE_API_KEY
environment variable to your private credential file. How you create it is explained below.
Do not share this file or make it publicly available as it is supposed to be a private key file.
You also need to know about workbook id
and sheet name
which are explained below.
Please have a look at the provided example tests/example_run.py
to see how you can
use this package.
For every entry (i.e., row), it expects a unique identifier which is later used to find the same row and update entries. The entries should be given in a dictionary format where the keys correspond to the column headers. If a particular header does not exist, it is created automatically.
If you don't have a Google Sheet Credential JSON:
- Go to https://console.developers.google.com
- Create a project if you don't have any.
- Click on
Select a project
on top-left and then clickNEW PROJECT
on the pop-up window. - Enter a project name and continue. Location section is irrelevant.
- The project you just created should be selected automatically. If not, select it and continue with the next step.
- Click on
- Click on
ENABLE APIS AND SERVICES
- Search for Google Sheets API and navigate.
- Enable it.
- On the next window, click on
Create Credentials
button.- Answers to the questions on this page: Google Sheets API, Web server, Application data and No. Click on
What credentials do I need?
button - Enter a name for the service account and assign Project > Editor role. Select
JSON
as the key type and continue. - Your JSON key file is downloaded automatically. Keep it wisely.
- Answers to the questions on this page: Google Sheets API, Web server, Application data and No. Click on
If you have a Google Sheet Credential JSON:
- In the JSON key file, you will see
client_email
entry. Google Sheet files must be shared with this account in order to get access. Similarly, you can simply add accounts of the other contributors.- Click on
Share
on top-right. - Enter
client_email
and share withEditor
permission.
- Click on
- Or, you can make your Google Sheet publicly available. Everyone with your file's workbook id can access.
- Click on
Share
on top-right. - Under the
Get link
section, click onChange
and selectAnyone with the link
option withEditor
role.
- Click on
You can create a Google Sheet file in your Google Drive. The workbook address can be found in the URL as follows:
docs.google.com/spreadsheets/d/1Ppq9okztrceM2Ym2UAz_GQfRKKmJUx3O4R9IFKGUvXw
/edit#gid=0
The sheet name is by default Sheet1
for a new file where you can give any names.