Skip to main content

$ posidrive

This Python library aims to make easier use Google Drive to backup/restore your data.

Installation

pip install posidrive

Install latest development version:

pip install git+https://github.com/Positeral/posidrive

Quickstart

Let's write a simple gd.py script:

from posidrive.gdrive import GoogleDrive

gdrive = GoogleDrive(folder='test')
gdrive.cli()

Run it from command line:

python gd.py
Usage: gd.py [OPTIONS] COMMAND [ARGS]...

Options:
  --debug  Enable debug mode.
  --help   Show this message and exit.

Commands:
  auth      Authorize Google account and save credentials.
  status    Show common information.
  list      Show files in current remote folder.
  upload    Upload file to current remote folder.
  download  Download file by ID.
  delete    Delete file by ID.
  clear     Delete all files in folder.
python gd.py status
Service:               Google Drive
Current remote folder: test
Credentials file:      /home/arthur/projects/posidrive/.pgdcredentials
Authorization:         Not authorized (credentials absent)

Let's authorize the application now:

python gd.py auth
Please visit this URL to authorize this application: https://[...]
Enter the authorization code: 

Follow the link, authorize the application and paste the resulting code. By default, posidrive request you the minimal permissions. Сheck the status:

python gd.py status
Service:               Google Drive
Current remote folder: test
Credentials file:      /home/arthur/projects/posidrive/.pgdcredentials
Authorization:         Authorized
Account:               af3.inet@gmail.com
Usage:                 11.2G
Limit:                 15G

Good! Now you can use list, upload, download, delete or clear. Don't forget that every command have --help option.

Custom scripts

The following script make a compressed archive and upload it to Google Drive. Then, it will delete all remote files except the last three:

import os
import click
import tarfile

from posidrive.gdrive import GoogleDrive


class MyGoogleDrive(GoogleDrive):
    @GoogleDrive.cli.command('archive')
    @click.argument('path', required=True)
    def cmd_archive(self, path):
        '''Archive directory/file'''
        self.initialize()

        tarname = os.path.basename(path)+'.tar.lzma'
        tarpath = tarname

        tar = tarfile.open(tarpath, 'w:xz')
        tar.add(path)
        tar.close()

        self.cmd_upload(tarpath, tarname)
        self.cmd_clear(keep_last=3, yes=True)


gdrive = MyGoogleDrive(folder='test')
gdrive.cli()

Release files for posidrive 0.1.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 posidrive 0.1.1
File Size Uploaded
posidrive-0.1.1.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for posidrive 0.1.1
File Interpreter ABI Platform
posidrive-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / posidrive-0.1.1.tar.gz

Download URL posidrive-0.1.1.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ae2e02ad23e6d56d989cdbd58432497dd828cb3033a8d9784594dacf0b0d8765
BLAKE2b-256 checksum
How to use checksums
f8232a504464d32153308b9e15b48a95f5b04ee32b6e07cf118e03fc9b65151b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

Release files / posidrive-0.1.1-py3-none-any.whl

Download URL posidrive-0.1.1-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4dd81143447b1edb131b04a8c5e89f369d1b8d8efb9a7cb730a10e5be1a337d7
BLAKE2b-256 checksum
How to use checksums
85e0eabfbdc9157a5f39bbc9c9c06cfe33614f31aee7b292b020a9327091f8e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

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