How to Connect Google Drive to Python using PyDrive

The Ultimate PyDrive Tutorial

Sebastian Theiler
Analytics Vidhya

--

Adapted from a photo by Florian Olivo on Unsplash

PyDrive is a high-level Python wrapper for the Google Drive API. It allows you to easily upload, download, and delete files in your Google Drive from a Python script.

In this article we will cover:

  • Getting an API key from Google Drive
  • Installing PyDrive
  • Using PyDrive (authorization, creating files, searching for files, downloading, (un)trashing and deleting, uploading, etc.)
  • Using PyDrive in places without a web browser (e.g., Kaggle Kernels)
  • Examples of PyDrive in the real world

Feel free to skip to any section!

All the code we develop in this article will be available on my GitHub, here.

Getting Your API Key

First we need to enable the Google Drive API. To do that head over to this link, and click “Enable” (if you’ve already enabled the API for whatever reason, click “Manage”).

Then set your “User Type” as external, here, and click create. Next you’ll need to fill out the OAuth consent screen. All you need to do here is specify an application name.

--

--

Sebastian Theiler
Analytics Vidhya

This account is inactive now; thank you to everyone who has read my pieces! I’m so glad I could share some knowledge about AI and data science. I might return…