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=auth, verbose=True)
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=None, 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.get_storage_quota()
Get permission of a file or folder
drive.list_permissions(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
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file simple_drive-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: simple_drive-1.0.2-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05532d279c15914fda3d6c76adb05c33f42be312bab9ffc65036bec4738504c5 |
|
MD5 | 2350fc6c26c91d80d05e7f9a2edc7406 |
|
BLAKE2b-256 | 75d87dd349c67985fa3b5c65c5195eed6c2d886f18139aede3beb936259978a6 |