Skip to main content

Use Google Drive API in the simplest way

Project description

simple_drive

Use Google Drive API in the simplest way

Installation

Install from GitHub

pip install --upgrade git+https://github.com/tranngocminhhieu/simple-drive.git

Install from PyPI

pip install --upgrade simple-drive

Usage

Import

from simple_drive import Drive, Auth, MimeTypes, Roles

Create auth info

From a service account

Read more: How to create a Service Account

# Way 1
auth = Auth.from_service_account_file(file=YOUR_SERVICE_ACCOUNT_FILE)
# Way 2
auth = Auth.from_service_account_info(info=YOUR_SERVICE_ACCOUNT_INFO)

From local web server

auth = Auth.local_web_server(client_secrets_file=YOUR_CLIENT_SECRETS_FILE)

Use Drive API

drive = Drive(auth_info=auth)

Create a file or folder

# mime_type = MimeTypes.FOLDER
# mime_type = MimeTypes.SHEETS
# ...
drive.create(name, mime_type, dest_folder_id=None)

Delete a file or folder

drive.delete(file_id)

Move a file or folder

drive.move(file_id, dest_folder_id)

Upload a file

drive.upload(file, dest_folder_id=None, rename=None)

Copy a file

Not support folder yet.

drive.copy(file_id, name_prefix='Copy of ', name_suffix='', dest_folder_id=None)

Rename a file or folder

drive.rename(file_id, name)

Get a file or folder info

drive.get_file_info(file_id, fields='*')

List files related to this account

drive.list_files(title_contains=None, owner_email=None, folder_id=None, custom_filter=None)

Get the account storage quota

drive.storage_quota()

Get permission of a file or folder

drive.get_permission_info(file_id)

Add permission to a file or folder

# role = Roles.VIEWER
# role = Roles.EDITOR
# role = Roles.COMMENTER
drive.add_permission(file_id, email, role)

Remove a permission from a file or folder

Please provide either email or permission_id.

drive.remove_permission(file_id, email=None, permission_id=None)

Transfer ownership of a file or folder to an email

Support emails in organization.

drive.transfer_ownership(file_id, email)

Conclusion

I welcome your contributions!

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

simple_drive-1.0.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file simple_drive-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_drive-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1371cb420d9af9e4fc4a360b67c91fd45e01059a326112e817ba90b385f62428
MD5 fff51ebd0dbd1d44cc9cdb5b9fb6d424
BLAKE2b-256 940957eeecb3e54bf40fba20e27a70cd8f16191c37ddc2d4a8d71838ef56b9e7

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