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
with open("image_path.png") as fp:
image_bytes = fp.read()
media = ...
image_bytes_b64 = base64.urlsafe_b64encode(image_bytes).decode('utf-8')
metadata = {
'contentHints': {
'thumbnail': {
'image': image_bytes_b64,
"mimeType": "image/png"
}
}
}
gdw.upload(media, **metadata)
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
Release history Release notifications | RSS feed
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.5.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for gdrivewrapper-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3960d69e99e7005e41a95df45a7ea20ada4bcd2b7495b47c691ff845da23fb1e |
|
MD5 | 15fead816240f516f2c9ed17142e5fc4 |
|
BLAKE2b-256 | f0a03e257709942b1bed9c0c0a930576cecae61f49ca3c9ca38d66b4d0865002 |