Skip to main content

google drive python


Library and cli to manage and interact with your Google Drive, sheets and docs

Table of Contents

  1. Introduction
  2. Obtaining credentials for Google APIs
  3. Installing google-drive CLI
  4. CLI Documentation
  5. Contributing
  6. License

Introduction

Build Status codecov Python PRs Welcome GitHub license

Obtaining credentials for Google APIs

Google API credentials

Create a Google project :zap:

Just access to Google APIs.

Create credentials for your project :key:

Once you have created your project, you can create your project's credentials.

To manage project's credentials you have the section api/credentials within Google APIs. But if this is your first credentials creation you better follow these steps:

  • First, you have to create the consent for your project
  • Once the consent is already created and you have a name for you google app you can create your credentials:
    • Go to + Create Credentials and select OAuth ID client
    • Or access to api/credentials/oauthclient
    • The OAuth client type is other and choose the name you prefer :smiley:

You have already created your credentials! :fireworks:

Just place them in a credentials.json file in the root of this repository. :heavy_exclamation_mark::heavy_exclamation_mark:

Enable Google APIs :books:

You can see where you have to access for each google api in the doc google apis usage

Generating your token.pickle :unlock:

To authenticate us we have to send a token.pickle to Google APIs, this token.pickle is generated using the file credentials.json.

To generate this we have the make target google-auth, so, you just have to tun

  • make google-auth

:warning: Credentials files to authenticate yourself are included in our .gitignore

:angel: So, you don't have to worry about that :smiley:

Installing google-drive CLI

Using make

make install

Using pip

pip install google-drive

With specific version

Look for available versions with:

pip install google-drive==

And select one and run:

pip install google-drive==<VERSION>

CLI Documentation

google-drive --help

Shows the help message

Usage

> google-drive --help
Usage: google-drive [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  get    Get file metadata
  get-mimetypes  Get Mimetypes availables in this API implementation
  login  Perform a login with google oauth
  ls     List directory contents
  mkdir  Make directory

google-drive get-mimetypes

Get Mimetypes availables in this API implementation

Usage

>  google-drive get-mimetypes credentials.json
  - application/vnd.google-apps.folder
  - application/vnd.google-apps.document
  - application/vnd.google-apps.spreadsheet
  - application/pdf

google-drive login

Perform a login with google oauth.

Usage

> google-drive login <path-to-credentials-file.json>

google-drive ls

List directory contents

Usage

> google-drive ls <directory>/<maybe-some-subdir> <path-to-credentials-file.json>
- (<GOOGLE_DOC_ID_1>, <FILENAME_1>, <FILE_MIMETYPE_1>)
- (<GOOGLE_DOC_ID_2>, <FILENAME_2>, <FILE_MIMETYPE_2>)
- (<GOOGLE_DOC_ID_3>, <FILENAME_3>, <FILE_MIMETYPE_3>)
...
- (<GOOGLE_DOC_ID_N>, <FILENAME_N>, <FILE_MIMETYPE_N>)

google-drive get

Get file metadata

Usage

> google-drive get <GOOGLE_DOC_ID> <path-to-credentials-file.json>

File Metadata:
==
id: <GOOGLE_DOC_ID>
name: <FILENAME>
parents: ['<GOOGLE_DOC__PARENT_ID>']
mime_type: <FILE_MIMETYPE>
export_links:
  - application/rtf: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=rtf
  - application/vnd.oasis.opendocument.text: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=odt
  - text/html: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=html
  - application/pdf: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=pdf
  - application/epub+zip: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=epub
  - application/zip: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=zip
  - application/vnd.openxmlformats-officedocument.wordprocessingml.document: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=docx
  - text/plain: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=txt

google-drive mkdir

Make directory

Usage

> google-drive mkdir <DIR_NAME> <path-to-credentials-file.json>
(<GOOGLE_DOC_ID>, <DIR_NAME>, application/vnd.google-apps.folder)

google-drive touch

Create empty file of specified mimetype

Usage

> google-drive touch <EXISTING_DIR>/<FILENAME> <SOME_MYMETYPE> <path-to-credentials-file.json>
(<GOOGLE_DOC_ID>, <FILENAME>, <SOME_MYMETYPE>)

It could raise MissingGoogleDriveFolderException when parent directories do not exist.

Using googledrive as API SDK

Contributing

PRs Welcome

Contributions are welcome! Please see our Contributing Guide and Style Guide for more details.

You can visit our TODO list :)

License

This project is licensed under the Apache license.

Metadata

Release files for google-drive 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for google-drive 0.5.1
File Size Uploaded
google-drive-0.5.1.tar.gz 16.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for google-drive 0.5.1
File Interpreter ABI Platform
google_drive-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.5 kB

Release files / google-drive-0.5.1.tar.gz

Download URL google-drive-0.5.1.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7ccf6a6b1ceb36d0f2719268caa6268ec9d4443495dac4168b632f7177dbb0b1
BLAKE2b-256 checksum
How to use checksums
dedcb184be11ecfbd9884b4a70a1ab675c6c9eff65fcad698175fef258b3da9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / google_drive-0.5.1-py3-none-any.whl

Download URL google_drive-0.5.1-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
479d704b3737b005dba7b8f9c8bd4566b8562e1a88b56b66fe0a0634d99a9900
BLAKE2b-256 checksum
How to use checksums
fabcff28f6b41cfdac511ddc3086bb47a6045f9ca947fa9b921cdbe278f95cbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page