Skip to main content

File management tools for Google Drive based on PyDrive

Project description

gdrive2

What is gdrive2?

Documentation Status GitHub license GitHub release

gdrive2 helps users to easily access files from Google Drive using paths, instead of File ids. Google API requires the users to know the File ID to access it, but this package which is built using the pyDrive package allows users to use a file path to access the file or folder.

In addition to this, the package also provides commands that can be called from a terminal, like cd, ls, pull or push, to quickly view, modify, download or upload files from or to Google drive using a python code or just the command line.

Setup:

pip install -i https://test.pypi.org/simple/ gdrive2

Documentation:

For more details about setup and commands, check gdrive2.readthedocs.io.

Quickdemo 1 : Basics

Lets see how gdrive2 can be used from command line.

Open terminal and set some folder where you intend to download or from where you intend to upload files.

$ gd init

When asked for a username, this is not same as the google username. More about this explained in the username documentation. Enter some nickname (for example, mygdrive2) you would like to give to your google account, so that you can use this for quick authentication into your account in future. This should take you to a Oauth Consent screen, where you'll be asked to enter your Google username and password. You are good, if you see this a html page showing this.

The authentication is successful.

Once authentication is done, from the current working folder, you can try several gdrive2 commands. Just like git, gdrive2 also creates a hidden folder .gd which contains information about the fileIDs, driveIDs etc. More about this explained in the parents documentation.

:warning: After authentication of a new account, the credentials are stored in ROOT_PATH/api_data folder. The contents of this folder must be handled with discretion.

After, initialization and authentication, you can use all the gdrive2 commands from this directory.

$ gd status
---------------
Parent dicts :
---------------
// origin // 
username : mygdrive2
path     : ''
id       : 'root'
drive    : 'My Drive'
driveId  : 'root'
client_sec : 'client_secrets'

No files/folders staged.

This command shows the contents of .gd/.gdinfo.json file created during initialization. The structure of this and the meaning of each term are explained in the parents documentation. For example, the folders in my drive are in this hierarchy.

My Drive
|
|___fruits
|      |___hard
|      |     |__apple.jpg
|      |     |__guava.png
|      |
|      |___soft
|            |__grapes.jpg
|
|___flowers
      |___yellow
      |      |__sunflower.tiff
      |
      |___red
	   |__roses.jpg
	   |__poppy.png

To list my files in the path stored in the path variable of the dictionary showed above:

$ gd ls
: D[2351.5kB] 1 : fruits
: D[6571.2kB] 2 : flowers
 

My Drive is the name of the google drive's root folder. '' (empty string) denotes the path to it. This shows that there are two folders in my root folder - fruits and flowers.

$ gd ls fruits/hard
: f[1000.5kB] 1 : apple.jpg
: F[321.0kB] 2 : guava.jpg

This is how the paths can be simply used to get the file contents. Now, I'll change my path from '' to 'fruits/hard':


$ gd cd fruits/hard
origin cwd changed to 'fruits/hard'

$ gd ls
: f[1000.5kB] 1 : apple.jpg
: F[321.0kB] 2 : guava.jpg

$ gd status
---------------
Parent dicts :
---------------
// origin // 
username : mygdrive2
path     : 'fruits/hard'
id       : '34eWf..iT23'
drive    : 'My Drive'
driveId  : 'root'
client_sec : 'client_secrets'

No files/folders staged.

If I want to download the folder:

$ gd pull

Or, to just download the apple.jpg:

$ gd pull origin apple.jpg

If I want to upload berry.png to fruits/hard:

$ gd add 
$ gd cd fruits/hard
$ gd push

Quickdemo 2 : Multiple Parent functionality

.gd/.gdinfo.json is a dictionary with each key defined as a parent (just like a remote in git). The first key of this dictionary is 'default_parent' whose value is the name of a default parent. Multiple parents can be set with multiple usernames(i.e. google accounts), paths, shared drives or even different client secrets files and one of these can be given the status of 'default_parent'. This makes frequent uploading and downloading as easy as git pull and push functions.

To add a new parent:

$ git init -add

Once a parent is added (say, origin2), we can assign different parameters (like username, path etc.) and push files simultaneously

$ git push origin origin2

Quickdemo 3 : Use of these commands in python script:

All these commands can be used in a python script as shown below. The only difference from the terminal commands is that apart from the main function (init, status, etc), the optional arguements must be passed as strings in a list. If there is no arguements, an empty list must be passed in the function.

>> import gdrive2 as gd
>> 
>> gd.init([])
>> gd.status([])
>> gd.add(['berry.jpg', 'mango.jpg'])

For more details, check gdrive2.readthedocs.io

Please post issues here or email me at preeth@uw.edu

Project details


Download files

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

Source Distribution

gdrive2-0.7.0.tar.gz (40.8 kB view details)

Uploaded Source

Built Distribution

gdrive2-0.7.0-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file gdrive2-0.7.0.tar.gz.

File metadata

  • Download URL: gdrive2-0.7.0.tar.gz
  • Upload date:
  • Size: 40.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for gdrive2-0.7.0.tar.gz
Algorithm Hash digest
SHA256 d28ee7132089dfb93ea679763f61e958b7199b0d20aa84aff0a39b5f4b12239f
MD5 178c1050e5df4dd3787763ac2aaf4de2
BLAKE2b-256 45bc76f42130746f939fe15950172adc3a2d63e540b127bcce756204677584eb

See more details on using hashes here.

File details

Details for the file gdrive2-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: gdrive2-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 41.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for gdrive2-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4886c659014f6a619b4d4c1ae4a75eb25831c38567ced72afd586e46df254c23
MD5 9b2d79593c4a31b7d11916e880d8785f
BLAKE2b-256 741f0da3192968a1a593fe72df70fdf1f0f11f3ffe370609580ee270a1fac65e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page