A collection of usefull tools to interact with the google drive/google docs api.
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 SCOPES = [ 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/documents', 'https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/presentations' ] # 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
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
You can test the library using the given
Enable the Google Drive and Docs Api and Download the Client Configuration
In order the script to work you need to have a valid
which contains your google drive credentials.
For the example, you only need to activate the Google Drive and Google Sheets
api with your account.
- Navigate to https://developers.google.com/drive/api/v3/quickstart/python
- Click on the Enable the Drive Api Button
- Navigate to https://developers.google.com/docs/api/quickstart/python
- Click on the Enable the Docs Api Button
- Click on Download Client Configuration Button
- Move the downloaded
credentials.jsonfile to this directory.
Install the Dependencies
There are two ways how to install the dependencies.
If you use pip natively, you can simply install the dependencies from
requirements.txt file using
pip install -r requirements.txt.
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
To run the example script in the virtual environnement, created by pipenv, you can
pipenv run python example.py.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|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|
Hashes for gdrive_tools-1.0.1-py3-none-any.whl