Read/Write Google Sheet With 5 Lines Of Python Code

codeforests
The Startup
Published in
7 min readNov 22, 2020

--

Photo by Niclas Illg on Unsplash

Introduction

Google Sheet is a very powerful tool in terms of collaboration, it allows multiple users to work on the same rows of data simultaneously. It also provides fine-grained APIs in various programming languages for your application to connect and interact with Google Sheet. Sometimes when you just need some simple operations like reading/writing data from a sheet, you may wonder if there is any higher level APIs that can complete these simple tasks easily. The short answer is yes.

In this article, we will be discussing how can we read/write Google Sheet in 5 lines of Python code.

Prerequisites

As the prerequisite, you will need to have a Google service account in order for you to go through the Google cloud service authentication for your API calls. You can follow the guide from here for a free account setup. Once you have completed all the steps, you shall have a JSON file similar to below which contains your private key for accessing the Google cloud service. You may rename it to “client_secret.json” for our later use.

{ 
"type": "service_account",
"project_id": "new_project",
"private_key_id": "xxxxxxx",
"private_key": "-----BEGIN PRIVATE KEY-----\xxxxx\n-----END PRIVATE KEY-----\n",
"client_email"…

--

--

codeforests
The Startup

Resources and tutorials for python, data science and automation solutions