Skip to main content

A collection of usefull tools to interact with the google drive/google docs api.

Project description

GDrive Tools

Goal of this Project

The automated managing of google drive documents is quite laborious. This is because of the Google Drive API v3, which does not allow to pass a directory path of a document that should be created. Instead, documents are only ordered using the parents node id.

Since its more common for us to think in directory trees, its more convenient for us to specify a full path.

This Project offers a method to create and move documents to a real path instead of just providing the parents node Id (as its needed by the Google Drive Api).


The usage of this library should be straight forward. Firstly, you have to create a library client which only needs your credentials. This can be archived like so:

import gdrive_tools.gdrive_tools as gt
import gdrive_tools.google_auth as ga
from gdrive_tools.google_filetypes import GoogleFiletypes


# Create a google auth object which wraps the authentication on the google
# drive api.
auth = ga.GoogleAuth(SCOPES)
credentials = auth.createCredentials()

# Create the api client and pass the read credentials.
googleDriveToolsClient = gt.GoogleDriveTools(credentials)

If the client object was created, you can use the offered methods.

Create a new Document

A new document can be created using the createFile() method. The created document will be placed inside a directory with the given path. Any nonexisting directories will be created.

Directories which are placed in the drives trash folder will be ignored.

The following parameters are needed:

  • destination(str): Full path, where the document should be moved to. The root is either the shared drive with the given name or just the root directory of your local drive (if you want to create a new document on your local drive). All directories are delimited by a simple slash (/).
  • documentName(str): Name of the Document that should be created.
  • fileType(int): Type of the document. Currently, the following types are supported:
    • GoogleFiletypes.DOCUMENT: Google Docs file
    • GoogleFiletypes.SHEET: Google Sheets file
    • GoogleFiletypes.SLIDE: Google Slides file

Move a Document

A document can be moved from one directory to another, either inside your local or a shared drive, using the moveDocument() method.

The following parameters are needed.

  • sourcePath(str): The full source path of the document that should be moved. The root is either the shared drive with the given name or just the root directory of your local drive (if you want to move a document on your local drive).
  • destinationPath(str): The target path where the document should be moved to. The root point of this path points to the root directory of the shared drive with the name, defined by the sourcePath parameter.


You can test the library using the given script.

Enable the Google Drive and Docs Api and Download the Client Configuration

In order the script to work you need to have a valid credentials.json file, which contains your google drive credentials. For the example, you only need to activate the Google Drive and Google Sheets api with your account.

  1. Navigate to
  2. Click on the Enable the Drive Api Button
  3. Navigate to
  4. Click on the Enable the Docs Api Button
  5. Click on Download Client Configuration Button
  6. Move the downloaded credentials.json file to this directory.

Install the Dependencies

There are two ways how to install the dependencies.

Using Pip

If you use pip natively, you can simply install the dependencies from the requirements.txt file using pip install -r requirements.txt.

Using Pipenv

This project's dependencies can also be managed with Pipenv. To use Pipenv, make sure its installed on your system (if not it can be done so by executing pip install pipenv). Then you can install the dependencies using pipenv install.

To run the example script in the virtual environnement, created by pipenv, you can run pipenv run python

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gdrive-tools, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size gdrive_tools-1.0.1-py3-none-any.whl (8.2 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size gdrive-tools-1.0.1.tar.gz (6.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page