Skip to main content

A wrapper around Google Drive SDK

Project description

gdrivewrapper

A wrapper around Google Drive SDK. Covers basic operations like uploading a file or creating a folder.

Usage

Initiate the wrapper class

from gdrivewrapper import GDriveWrapper

api_scope = "https://www.googleapis.com/auth/drive.file"
creds_path = "./drive_v3_creds.json"

gdw = GDriveWrapper(api_scope, creds_path)

Upload a local file

from googleapiclient.http import MediaFileUpload

local_path = "/tmp/resources/hello.txt"
media = MediaFileUpload(local_path)
gdw.upload(media)

Upload a string

from googleapiclient.http import MediaInMemoryUpload

my_bytearray = "my string :)".encode('utf-8')
media = MediaInMemoryUpload(my_bytearray)
gdw.upload(media)

Upload with a filename

media = ...
gdw.upload(media, name="mytextfile.txt")

Upload with a thumbnail

import base64

media = ...

with open("image_path.png") as fp:
    image_bytes = fp.read()

gdw.upload(media, thumbnail=image_bytes)

Upload to a folder

response = gdw.create_folder("myfolder1")

media = ...
gdw.upload(media, folder_id=response["id"])

Add a comment to an existing file

media = ...
response = gdw.upload(media)
gdw.create_comment(key=response["id"], comment="this file is great!")

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

gdrivewrapper-0.0.17.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

gdrivewrapper-0.0.17-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

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