# fw-gdrive
Helper library that provides a set of utilities to integrate Google Drive
for common tasks including uploading files, deleting files and modifying Google Documents.
## Installation
Add as a `poetry` dependency to your project:
```bash
poetry add fw-gdrive
```
## Usage
### Instantiate Google API Client
```python
from fw_gdrive import gapi
# Specify the Drive API scopes
DEFAULT_GOOGLE_API_SCOPE = [
# Default Drive API scopes
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.appdata",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive.metadata",
"https://www.googleapis.com/auth/drive.metadata.readonly",
"https://www.googleapis.com/auth/drive.photos.readonly",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/drive.scripts",]
# instantiate Google API Client
google_api_client = gapi.GoogleAPIClient(service_cred_path=<path-to-credentials>, scopes=DEFAULT_GOOGLE_API_SCOPE)
# use the API Client to instantiate a Google Drive Folder object
gdrive_folder_obj = gapi.GoogleDriveFolder(folder_id=<folder-id>, api_client=google_api_client)
```
### Upload file to Google Drive Folder
Once you have instantiated a Google Drive Folder object
you can use `upload_file` method to upload file to that folder.
```python
gdrive_folder_obj = gapi.GoogleDriveFolder(folder_id=<folder-id>, api_client=google_api_client)
gdocs_file_obj = gdrive_folder_obj.upload_file(file_name=<name-of-file-you-uploading>, file_path=<path-to-file-you-uploading>)
```
### Modify Google Documents File content
There's a few handy method under `fw_gdrive.utils`
that allow you to build request to
modify the Google Documents file.
Here is a quick example of how to
replace text in the documents using `gapi.utils.replace_text`
```python
from fw_gdrive import utils
replace_text_request = utils.replace_text(targeted_text="dummy name",
replacement_text="a better name")
update_gear_name_result = google_docs_file_obj.update_document_request(request_call=[replace_text_request])
```
## License
PUBLIC:
[![MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/flywheel-io/tools/lib/fw-gdrive",
"name": "fw-gdrive",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "Flywheel",
"author": "Flywheel",
"author_email": "support@flywheel.io",
"download_url": "",
"platform": null,
"description": "# fw-gdrive\n\nHelper library that provides a set of utilities to integrate Google Drive\nfor common tasks including uploading files, deleting files and modifying Google Documents.\n\n## Installation\n\nAdd as a `poetry` dependency to your project:\n\n```bash\npoetry add fw-gdrive\n```\n\n## Usage\n\n### Instantiate Google API Client\n\n```python\nfrom fw_gdrive import gapi\n# Specify the Drive API scopes\nDEFAULT_GOOGLE_API_SCOPE = [\n # Default Drive API scopes\n \"https://www.googleapis.com/auth/drive\",\n \"https://www.googleapis.com/auth/drive.appdata\",\n \"https://www.googleapis.com/auth/drive.file\",\n \"https://www.googleapis.com/auth/drive.metadata\",\n \"https://www.googleapis.com/auth/drive.metadata.readonly\",\n \"https://www.googleapis.com/auth/drive.photos.readonly\",\n \"https://www.googleapis.com/auth/drive.readonly\",\n \"https://www.googleapis.com/auth/drive.scripts\",]\n\n# instantiate Google API Client\ngoogle_api_client = gapi.GoogleAPIClient(service_cred_path=<path-to-credentials>, scopes=DEFAULT_GOOGLE_API_SCOPE)\n\n# use the API Client to instantiate a Google Drive Folder object\ngdrive_folder_obj = gapi.GoogleDriveFolder(folder_id=<folder-id>, api_client=google_api_client)\n```\n\n### Upload file to Google Drive Folder\n\nOnce you have instantiated a Google Drive Folder object\nyou can use `upload_file` method to upload file to that folder.\n\n```python\ngdrive_folder_obj = gapi.GoogleDriveFolder(folder_id=<folder-id>, api_client=google_api_client)\ngdocs_file_obj = gdrive_folder_obj.upload_file(file_name=<name-of-file-you-uploading>, file_path=<path-to-file-you-uploading>)\n```\n\n### Modify Google Documents File content\n\nThere's a few handy method under `fw_gdrive.utils`\nthat allow you to build request to\nmodify the Google Documents file.\nHere is a quick example of how to\nreplace text in the documents using `gapi.utils.replace_text`\n\n```python\nfrom fw_gdrive import utils\nreplace_text_request = utils.replace_text(targeted_text=\"dummy name\", \n replacement_text=\"a better name\")\nupdate_gear_name_result = google_docs_file_obj.update_document_request(request_call=[replace_text_request])\n```\n\n## License\n\nPUBLIC:\n[![MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Flyweheel Google Drive Integration Tools",
"version": "0.3.3",
"split_keywords": [
"flywheel"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3140e3f75fdab761870a3e1e6d28429bc65e6e4e57698cb8b35ccdc0f61574c9",
"md5": "9f80e0e806e8b87e66ec3e586d0f4e2e",
"sha256": "242cca9d191856380911a642b1d5628f480ba22450e69570596d975191c89c4e"
},
"downloads": -1,
"filename": "fw_gdrive-0.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9f80e0e806e8b87e66ec3e586d0f4e2e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 9280,
"upload_time": "2023-04-27T16:48:55",
"upload_time_iso_8601": "2023-04-27T16:48:55.596593Z",
"url": "https://files.pythonhosted.org/packages/31/40/e3f75fdab761870a3e1e6d28429bc65e6e4e57698cb8b35ccdc0f61574c9/fw_gdrive-0.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-27 16:48:55",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "fw-gdrive"
}