{ "info": { "author": "Kanshi TANAIKE", "author_email": "tanaike@hotmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3.5" ], "description": "# gdoctableapppy\n\n[![Build Status](https://travis-ci.org/tanaikech/gdoctableapppy.svg?branch=master)](https://travis-ci.org/tanaikech/gdoctableapppy)\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENCE)\n\n\n\n# Overview\n\nThis is a python library to manage the tables on Google Document using Google Docs API.\n\n# Description\n\nGoogle Docs API has been released. When I used this API, I found that it is very difficult for me to manage the tables on Google Document using Google Docs API. Although I checked [the official document](https://developers.google.com/docs/api/how-tos/tables), unfortunately, I thought that it's very difficult for me. So in order to easily manage the tables on Google Document, I created this library.\n\n## Features\n\n- All values can be retrieved from the table on Google Document.\n- Values can be put to the table.\n- Delete table, rows and columns of the table.\n- New table can be created by including values.\n- Append rows to the table by including values.\n\n## Languages\n\nI manages the tables on Google Document using several languages. So I created the libraries for 3 languages which are golang, node.js and python. Google Apps Script has Class DocumentApp. So I has never created the GAS library yet.\n\n- [go-gdoctableapp](https://github.com/tanaikech/go-gdoctableapp)\n- [node-gdoctableapp](https://github.com/tanaikech/node-gdoctableapp)\n- [gdoctableapppy](https://github.com/tanaikech/gdoctableapppy)\n\n# Install\n\n```bash\n$ pip install gdoctableapppy\n```\n\nYou can also see this library at [https://pypi.org/project/gdoctableapppy/](https://pypi.org/project/gdoctableapppy/).\n\n# Method\n\n| Method | Explanation |\n| :------------------------------------------------ | :---------------------------------------------- |\n| [`GetTables()`](#gettables) | Get all tables from Document. |\n| [`GetValues()`](#getvalues) | Get values from a table from Document. |\n| [`SetValues()`](#setvalues1) | Set values to a table with 2 dimensional array. |\n| [`SetValues(`](#setvalues2) | Set values to a table with an object. |\n| [`DeleteTable()`](#deletetable) | Delete a table. |\n| [`DeleteRowsAndColumns()`](#deleterowsandcolumns) | Delete rows and columns of a table. |\n| [`CreateTable()`](createtable) | Create new table including sell values. |\n| [`AppendRow()`](#appendrow) | Append row to a table by including values. |\n\nThis library uses [google-api-python-client](https://github.com/googleapis/google-api-python-client).\n\n## Response\n\nThis library returns the following value.\n\n```python\n{\n 'tables': [],\n 'values': [],\n 'responseFromAPIs': [],\n 'libraryVersion': version\n}\n```\n\n- When `GetTables()` is used, you can see the values with `tables`.\n- When `GetValues()` is used, you can see the values with `values`.\n- When other methods are used and the option of `showAPIResponse` is `true`, you can see the responses from APIs which were used for the method. And also, you can know the number of APIs, which were used for the method, by the length of array of `responseFromAPIs`.\n\n# Usage\n\nAbout the authorization, please check the section of [Authorization](#authorization). In order to use this library, it is required to confirm that [the Quickstart](https://developers.google.com/docs/api/quickstart/python) works fine.\n\n## Scope\n\nIn this library, using the scope of `https://www.googleapis.com/auth/documents` is recommended.\n\n\n\n## 1. GetTables\n\nGet all tables from Document. All values, table index and table position are retrieved.\n\n### Sample script\n\nThis sample script retrieves all tables from the Google Document of document ID.\n\n```python\nresource = {\n \"oauth2\": creds,\n \"documentId\": documentId,\n # \"showAPIResponse\": True\n}\nres = gdoctableapp.GetTables(resource) # You can see the retrieved values like this.\nprint(res)\n```\n\n- `documentId`: Document ID.\n- `oauth2`: Credentials for using Docs API. Please check the section of [Authorization](#authorization).\n - If you want to use Service Account, please use `service_account` instead of `oauth2`. About this, please check [the sample script for Service account](#serviceaccount).\n- `showAPIResponse`: When `showAPIResponse: true` is used to `resource`, the responses from Docs API can be seen. The default value is `false`. **This option can be used for all methods.**\n\n\n\n## 2. GetValues\n\nGet values from the table. All values are retrieved.\n\n### Sample script\n\nThis sample script retrieves the values from 1st table in Google Document. You can see the retrieved values as `[][]string`. Because when the values are retrieved by Docs API, all values are automatically converted to the string data.\n\n```python\nresource = {\n \"oauth2\": creds,\n \"documentId\": \"###\",\n \"tableIndex\": 0,\n}\nres = gdoctableapp.GetValues(resource)\nprint(res) # You can see the retrieved values like this.\n```\n\n- `documentId`: Document ID.\n- `tableIndex`: Table index. If you want to use the 3rd table in Google Document. It's 2. The start number of index is 0.\n- `oauth2`: Credentials for using Docs API. Please check the section of [Authorization](#authorization).\n - If you want to use Service Account, please use `service_account` instead of `oauth2`. About this, please check [the sample script for Service account](#serviceaccount).\n\n\n\n## 3. SetValues 1\n\nThere are 2 patterns for putting values to the table. In this section, set values to the table with 2 dimensional array. When the rows and columns of values which are put are over those of the table, this method can automatically expand the rows and columns.\n\n### Sample script\n\nThis sample script puts the values to the first table in Google Document.\n\n```python\nresource = {\n \"oauth2\": creds,\n \"documentId\": \"###\",\n \"tableIndex\": 0,\n \"values\": [[\"a1\", \"b1\"], [\"a2\", \"b2\"], [\"a3\", \"b3\", \"c3\"]]\n}\nres = gdoctableapp.SetValues(resource) # You can see the retrieved responses from Docs API.\nprint(res)\n```\n\n- `documentId`: Document ID.\n- `tableIndex`: Table index. If you want to use the 3rd table in Google Document. It's 2. The start number of index is 0.\n- `oauth2`: Credentials for using Docs API. Please check the section of [Authorization](#authorization).\n - If you want to use Service Account, please use `service_account` instead of `oauth2`. About this, please check [the sample script for Service account](#serviceaccount).\n- `values`: `[][]string`\n\n### Result\n\nWhen above script is run, the following result is obtained.\n\n#### From:\n\n![](images/fig1.png)\n\n#### To:\n\n![](images/fig2.png)\n\n\n\n## 4. SetValues 2\n\nThere are 2 patterns for putting values to the table. In this section, set values to a table with an object. In this method, you can set the values using the range. When the rows and columns of values which are put are over those of the table, this method can automatically expand the rows and columns.\n\n### Sample script\n\nThis script puts the values with the range to the first table in Google Document.\n\n```python\nresource = {\n \"oauth2\": creds,\n \"documentId\": \"###\",\n \"tableIndex\": 0,\n \"values\": [\n {\n \"values\": [[\"A1\"], [\"A2\", \"B2\", \"c2\", \"d2\"], [\"A3\"]],\n \"range\": {\"startRowIndex\": 0, \"startColumnIndex\": 0}\n },\n {\n \"values\": [[\"B1\", \"C1\"]],\n \"range\": {\"startRowIndex\": 0, \"startColumnIndex\": 1}\n }\n ]\n}\nres = gdoctableapp.SetValues(resource) # You can see the retrieved responses from Docs API.\nprint(res)\n```\n\n- `documentId`: Document ID.\n- `tableIndex`: Table index. If you want to use the 3rd table in Google Document. It's 2. The start number of index is 0.\n- `oauth2`: Credentials for using Docs API. Please check the section of [Authorization](#authorization).\n - If you want to use Service Account, please use `service_account` instead of `oauth2`. About this, please check [the sample script for Service account](#serviceaccount).\n- `range.startRowIndex` of `values`: Row index of `values[0][0]`.\n- `range.startColumnIndex` of `values`: Column index of `values[0][0]`.\n- `values` : Values you want to put.\n\nFor example, when the row, column indexes and values are 1, 2 and \"value\", respectively, \"value\" is put to \"C3\".\n\n### Result\n\nWhen above script is run, the following result is obtained.\n\n#### From:\n\n![](images/fig1.png)\n\n#### To:\n\n![](images/fig3.png)\n\n\n\n## 5. DeleteTable\n\n### Sample script\n\nThis script deletes the first table in Google Document.\n\n```python\nresource = {\n \"oauth2\": creds,\n \"documentId\": \"###\",\n \"tableIndex\": 0\n}\nres = gdoctableapp.DeleteTable(resource)\nprint(res) # You can see the retrieved responses from Docs API.\n```\n\n- `documentId`: Document ID.\n- `tableIndex`: Table index. If you want to use the 3rd table in Google Document. It's 2. The start number of index is 0.\n- `oauth2`: Credentials for using Docs API. Please check the section of [Authorization](#authorization).\n - If you want to use Service Account, please use `service_account` instead of `oauth2`. About this, please check [the sample script for Service account](#serviceaccount).\n\n\n\n## 6. DeleteRowsAndColumns\n\n### Sample script\n\nThis script deletes rows of indexes of 3, 1 and 2 of the first table in Google Document. And also this script deletes columns of indexes of 2, 1 and 3.\n\n```python\nresource = {\n \"oauth2\": creds,\n \"documentId\": \"###\",\n \"tableIndex\": 0,\n \"deleteRows\": [3, 1, 2], # Start index is 0.\n \"deleteColumns\": [2, 1, 3] # Start index is 0.\n}\nres = gdoctableapp.DeleteRowsAndColumns(resource)\nprint(res) # You can see the retrieved responses from Docs API.\n```\n\n- `documentId`: Document ID.\n- `tableIndex`: Table index. If you want to use the 3rd table in Google Document. It's 2. The start number of index is 0.\n- `oauth2`: Credentials for using Docs API. Please check the section of [Authorization](#authorization).\n - If you want to use Service Account, please use `service_account` instead of `oauth2`. About this, please check [the sample script for Service account](#serviceaccount).\n- `deleteRows` : Indexes of rows you want to delete.\n- `deleteColumns` : Indexes of columns you want to delete.\n\n\n\n## 7. CreateTable\n\n### Sample script\n\nThis script creates new table to the top of Google Document, and the cells of the table have values.\n\n```python\nresource = {\n \"oauth2\": creds,\n \"documentId\": \"###\",\n \"rows\": 3,\n \"columns\": 5,\n \"createIndex\": 1,\n # \"append\": True, # When this is used instead of \"Index\", new table is created to the end of Document.\n \"values\": [[\"a1\", \"b1\"], [\"a2\", \"b2\"], [\"a3\", \"b3\", \"c3\"]]\n}\nres = gdoctableapp.CreateTable(resource)\nprint(res) # You can see the retrieved responses from Docs API.\n```\n\n- `documentId`: Document ID.\n- `oauth2`: Credentials for using Docs API. Please check the section of [Authorization](#authorization).\n - If you want to use Service Account, please use `service_account` instead of `oauth2`. About this, please check [the sample script for Service account](#serviceaccount).\n- `rows` : Number of rows of new table.\n- `columns` : Number of columns of new table.\n- `createIndex` : Index of Document for putting new table. For example, `1` is the top of Document.\n- `append` : When `append` is `true` instead of `createIndex`, the new table is created to the end of Google Document.\n- `values` : If you want to put the values when new table is created, please use this.\n\n### Result\n\nWhen above script is run, the following result is obtained. In this case, the new table is created to the top of Google Document.\n\n![](images/fig4.png)\n\n\n\n## 8. AppendRow\n\n### Sample script\n\nThis sample script appends the values to the first table of Google Document.\n\n```python\n resource = {\n \"oauth2\": creds,\n \"documentId\": \"###\",\n \"tableIndex\": 0,\n \"values\": [[\"a1\", \"b1\", \"c1\", 1, \"\", 2], [\"a2\", \"b2\", \"c2\", 1, \"\", 2]]\n }\n res = gdoctableapp.AppendRow(resource)\n print(res) # You can see the retrieved responses from Docs API.\n```\n\n- `documentId`: Document ID.\n- `tableIndex`: Table index. If you want to use the 3rd table in Google Document. It's 2. The start number of index is 0.\n- `oauth2`: Credentials for using Docs API. Please check the section of [Authorization](#authorization).\n - If you want to use Service Account, please use `service_account` instead of `oauth2`. About this, please check [the sample script for Service account](#serviceaccount).\n- `values` : Values you want to append to the existing table.\n\n### Result\n\nWhen above script is run, the following result is obtained. In this case, the values are put to the last row. And you can see that 3 columns are automatically added when the script is run.\n\n#### From:\n\n![](images/fig5.png)\n\n#### From:\n\n![](images/fig6.png)\n\n\n\n# Authorization\n\nThere are 2 patterns for using this library.\n\n## 1. Use OAuth2\n\nDocument of OAuth2 is [here](https://developers.google.com/identity/protocols/OAuth2).\n\n### Sample script\n\nIn this sample script, the authorization process uses [the Quickstart for Node.js](https://developers.google.com/docs/api/quickstart/nodejs). You can see the detail information at there.\n\n```python\nfrom __future__ import print_function\nimport pickle\nimport os.path\nfrom google_auth_oauthlib.flow import InstalledAppFlow\nfrom google.auth.transport.requests import Request\n\nfrom gdoctableapppy import gdoctableapp\n\n# If modifying these scopes, delete the file token.pickle.\nSCOPES = ['https://www.googleapis.com/auth/documents']\n\n\ndef main():\n \"\"\"Shows basic usage of the Docs API.\n Prints the title of a sample document.\n \"\"\"\n creds = None\n # The file token.pickle stores the user's access and refresh tokens, and is\n # created automatically when the authorization flow completes for the first\n # time.\n if os.path.exists('token.pickle'):\n with open('token.pickle', 'rb') as token:\n creds = pickle.load(token)\n # If there are no (valid) credentials available, let the user log in.\n if not creds or not creds.valid:\n if creds and creds.expired and creds.refresh_token:\n creds.refresh(Request())\n else:\n flow = InstalledAppFlow.from_client_secrets_file(\n 'credentials.json', SCOPES)\n creds = flow.run_local_server()\n # Save the credentials for the next run\n with open('token.pickle', 'wb') as token:\n pickle.dump(creds, token)\n\n resource = {\n \"oauth2\": creds,\n \"documentId\": \"###\",\n \"tableIndex\": 0,\n }\n res = gdoctableapp.GetValues(resource)\n print(res) # You can see the retrieved values like this.\n\n\nif __name__ == '__main__':\n main()\n```\n\n\n\n## 2. Use Service account\n\nDocument of Service account is [here](https://developers.google.com/identity/protocols/OAuth2ServiceAccount). When you use Service account, please share Google Document with the email of Service account.\n\n### Sample script\n\n```python\nfrom google.oauth2 import service_account\nfrom gdoctableapppy import gdoctableapp\n\nSCOPES = ['https://www.googleapis.com/auth/documents']\nSERVICE_ACCOUNT_FILE = 'service-account-credentials.json'\ncreds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)\n\nresource = {\n \"service_account\": creds,\n \"documentId\": \"###\",\n \"tableIndex\": 0,\n}\nres = gdoctableapp.GetValues(resource)\nprint(res) # You can see the retrieved values like this.\n```\n\n# Limitations\n\n- In the current stage, unfortunately, `tableCellStyle` cannot be modified by Google Docs API. By this, the formats of cells cannot be modified. About this, I have posted as [Feature Request](https://issuetracker.google.com/issues/135136221).\n\n# References:\n\n- Official document: [Inserting or deleting table rows](https://developers.google.com/docs/api/how-tos/tables#inserting_or_deleting_table_rows)\n- If you want to know the relationship between the index and startIndex of each cell, you can see it at [here](https://stackoverflow.com/a/56944149).\n\n---\n\n\n\n# Licence\n\n[MIT](LICENCE)\n\n\n\n# Author\n\n[Tanaike](https://tanaikech.github.io/about/)\n\nIf you have any questions and commissions for me, feel free to tell me.\n\n\n\n# Update History\n\n- v1.0.0 (July 18, 2019)\n\n 1. Initial release.\n\n[TOP](#top)\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tanaikech/gdoctableapppy", "keywords": "google document,google docs,docs api,table,manager,developer tools", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "gdoctableapppy", "package_url": "https://pypi.org/project/gdoctableapppy/", "platform": "", "project_url": "https://pypi.org/project/gdoctableapppy/", "project_urls": { "Homepage": "https://github.com/tanaikech/gdoctableapppy" }, "release_url": "https://pypi.org/project/gdoctableapppy/1.0.0/", "requires_dist": [ "google-api-python-client" ], "requires_python": "", "summary": "This is a python library to manage the tables on Google Document using Google Docs API.", "version": "1.0.0" }, "last_serial": 5548460, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "87ac91eb8747d977e8697e910f2fba39", "sha256": "e50844ae3853ea7272dae6b17da524044ba9c6eb6423baa4c0aa4413d272c767" }, "downloads": -1, "filename": "gdoctableapppy-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "87ac91eb8747d977e8697e910f2fba39", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11200, "upload_time": "2019-07-18T01:31:01", "url": "https://files.pythonhosted.org/packages/8f/79/963d2973c6f3326c9cc8dabd9151c44c13b63f67808ed85926ed609e501c/gdoctableapppy-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6b7173fff5038598c1dbc7dea485e276", "sha256": "e0ab0aab307375babd1acd16a43e008391ff47a10b518433c72393d612b01819" }, "downloads": -1, "filename": "gdoctableapppy-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6b7173fff5038598c1dbc7dea485e276", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10955, "upload_time": "2019-07-18T01:31:03", "url": "https://files.pythonhosted.org/packages/77/4b/c4f2bd63fdf032fd346b272291dc9605f118352e222d7c289409c961104a/gdoctableapppy-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "87ac91eb8747d977e8697e910f2fba39", "sha256": "e50844ae3853ea7272dae6b17da524044ba9c6eb6423baa4c0aa4413d272c767" }, "downloads": -1, "filename": "gdoctableapppy-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "87ac91eb8747d977e8697e910f2fba39", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11200, "upload_time": "2019-07-18T01:31:01", "url": "https://files.pythonhosted.org/packages/8f/79/963d2973c6f3326c9cc8dabd9151c44c13b63f67808ed85926ed609e501c/gdoctableapppy-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6b7173fff5038598c1dbc7dea485e276", "sha256": "e0ab0aab307375babd1acd16a43e008391ff47a10b518433c72393d612b01819" }, "downloads": -1, "filename": "gdoctableapppy-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6b7173fff5038598c1dbc7dea485e276", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10955, "upload_time": "2019-07-18T01:31:03", "url": "https://files.pythonhosted.org/packages/77/4b/c4f2bd63fdf032fd346b272291dc9605f118352e222d7c289409c961104a/gdoctableapppy-1.0.0.tar.gz" } ] }