{"id":17381873,"url":"https://github.com/tanaikech/getfilelistpy","last_synced_at":"2025-08-04T07:10:39.284Z","repository":{"id":41394686,"uuid":"157952301","full_name":"tanaikech/getfilelistpy","owner":"tanaikech","description":"This is a python library to retrieve the file list with the folder tree from the specific folder of Google Drive.","archived":false,"fork":false,"pushed_at":"2020-08-11T01:54:53.000Z","size":22,"stargazers_count":29,"open_issues_count":5,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-28T16:49:42.236Z","etag":null,"topics":["file-list","folder-structure","google-drive","google-drive-api","python","python-library"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tanaikech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-17T05:00:38.000Z","updated_at":"2025-03-29T07:40:17.000Z","dependencies_parsed_at":"2022-07-30T08:18:06.113Z","dependency_job_id":null,"html_url":"https://github.com/tanaikech/getfilelistpy","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tanaikech/getfilelistpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2Fgetfilelistpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2Fgetfilelistpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2Fgetfilelistpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2Fgetfilelistpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanaikech","download_url":"https://codeload.github.com/tanaikech/getfilelistpy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2Fgetfilelistpy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268660147,"owners_count":24286028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file-list","folder-structure","google-drive","google-drive-api","python","python-library"],"created_at":"2024-10-16T07:02:02.936Z","updated_at":"2025-08-04T07:10:39.247Z","avatar_url":"https://github.com/tanaikech.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# getfilelistpy\r\n\r\n[![Build Status](https://travis-ci.org/tanaikech/getfilelistpy.svg?branch=master)](https://travis-ci.org/tanaikech/getfilelistpy)\r\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENCE)\r\n\r\n\u003ca name=\"top\"\u003e\u003c/a\u003e\r\n\r\n# Overview\r\n\r\nThis is a python library to retrieve the file list with the folder tree from the specific folder of own Google Drive and shared Drives.\r\n\r\n# Description\r\n\r\nWhen I create applications for using Google Drive, I often retrieve a file list from a folder in the application. So far, I had created the script for retrieving a file list from a folder for each application. Recently, I thought that if there is the script for retrieving the file list with the folder tree from the folder of Google Drive as a library, it will be useful for me and other users. So I created this.\r\n\r\n## Features\r\n\r\n- This library retrieves all files from a folder in Google Drive.\r\n- All files include the folder structure in Google Drive.\r\n- Only folder tree can be also retrieved.\r\n\r\n# Install\r\n\r\n```\r\n$ pip install getfilelistpy\r\n```\r\n\r\nYou can also check this library at [https://pypi.org/project/getfilelistpy/](https://pypi.org/project/getfilelistpy/).\r\n\r\n# Method\r\n\r\n| Method                | Explanation                                            |\r\n| :-------------------- | :----------------------------------------------------- |\r\n| GetFolderTree(object) | Retrieve only folder structure from a folder           |\r\n| GetFileList(object)   | Retrieve file list with folder structure from a folder |\r\n\r\n# Usage\r\n\r\nThere are 3 patterns for using this library.\r\n\r\n## 1. Use API key\r\n\r\nThis is a sample script using API key. When you want to retrieve the API key, please do the following flow.\r\n\r\n1. Login to Google.\r\n2. Access to [https://console.cloud.google.com/?hl=en](https://console.cloud.google.com/?hl=en).\r\n3. Click select project at the right side of \"Google Cloud Platform\" of upper left of window.\r\n4. Click \"NEW PROJECT\"\r\n   1. Input \"Project Name\".\r\n   2. Click \"CREATE\".\r\n   3. Open the created project.\r\n   4. Click \"Enable APIs and get credentials like keys\".\r\n   5. Click \"Library\" at left side.\r\n   6. Input \"Drive API\" in \"Search for APIs \u0026 Services\".\r\n   7. Click \"Google Drive API\".\r\n   8. Click \"ENABLE\".\r\n   9. Back to [https://console.cloud.google.com/?hl=en](https://console.cloud.google.com/?hl=en).\r\n   10. Click \"Enable APIs and get credentials like keys\".\r\n   11. Click \"Credentials\" at left side.\r\n   12. Click \"Create credentials\" and select API key.\r\n   13. Copy the API key. You can use this API key.\r\n\r\n### Sample script\r\n\r\n```python\r\nfrom getfilelistpy import getfilelist\r\n\r\nresource = {\r\n    \"api_key\": \"#####\",\r\n    \"id\": \"### Folder ID ###\",\r\n    \"fields\": \"files(name,id)\",\r\n}\r\nres = getfilelist.GetFileList(resource)  # or r = getfilelist.GetFolderTree(resource)\r\nprint(res)\r\n```\r\n\r\n### Note\r\n\r\n- **When you want to retrieve the file list from the folder using API key, the folder is required to be shared.**\r\n- You can modify the property of `fields`. When this is not used, the default fields are used.\r\n\r\n## 2. Use OAuth2\r\n\r\nDocument of OAuth2 is [here](https://developers.google.com/identity/protocols/OAuth2).\r\n\r\n### Sample script 1\r\n\r\nIn this sample script for `oauth2client`.\r\n\r\n```python\r\nfrom httplib2 import Http\r\nfrom oauth2client import file, client, tools\r\nfrom getfilelistpy import getfilelist\r\n\r\nSCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'\r\n\r\nstore = file.Storage('token.json')\r\ncreds = store.get()\r\nif not creds or creds.invalid:\r\n    flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)\r\n    creds = tools.run_flow(flow, store)\r\n\r\nresource = {\r\n    \"oauth2\": creds.authorize(Http()),\r\n    \"id\": \"### Folder ID ###\",\r\n    \"fields\": \"files(name,id)\",\r\n}\r\nres = getfilelist.GetFileList(resource)  # or r = getfilelist.GetFolderTree(resource)\r\nprint(res)\r\n```\r\n\r\n\u003ca name=\"googleauthoauthlibsample\"\u003e\u003c/a\u003e\r\n\r\n### Sample script 2\r\n\r\nIn this sample script for `google_auth_oauthlib`, the process of OAuth2 uses [the quickstart of Google](https://developers.google.com/drive/api/v3/quickstart/python). Please check this.\r\n\r\n```python\r\nimport pickle\r\nimport os.path\r\nfrom google_auth_oauthlib.flow import InstalledAppFlow\r\nfrom google.auth.transport.requests import Request\r\nfrom getfilelistpy import getfilelist\r\n\r\nSCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'\r\n\r\ncreds = None\r\n\r\ncreFile = 'token.pickle'\r\nif os.path.exists(creFile):\r\n    with open(creFile, 'rb') as token:\r\n        creds = pickle.load(token)\r\nif not creds or not creds.valid:\r\n    if creds and creds.expired and creds.refresh_token:\r\n        creds.refresh(Request())\r\n    else:\r\n        flow = InstalledAppFlow.from_client_secrets_file(\r\n            'client_secret.json', SCOPES)\r\n        creds = flow.run_local_server()\r\n    with open(creFile, 'wb') as token:\r\n        pickle.dump(creds, token)\r\n\r\nresource = {\r\n    \"oauth2\": creds,\r\n    \"id\": \"### Folder ID ###\",\r\n    \"fields\": \"files(name,id)\",\r\n}\r\nres = getfilelist.GetFileList(resource)  # or r = getfilelist.GetFolderTree(resource)\r\nprint(res)\r\n```\r\n\r\n### Note\r\n\r\n- Here, as a sample, the script of the authorization uses the script of [quickstart](https://developers.google.com/drive/api/v3/quickstart/python).\r\n- You can modify the property of `fields`. When this is not used, the default fields are used.\r\n\r\n## 3. Use Service account\r\n\r\nDocument of Service account is [here](https://developers.google.com/identity/protocols/OAuth2ServiceAccount).\r\n\r\n### Sample script\r\n\r\n```python\r\nfrom google.oauth2 import service_account\r\nfrom getfilelistpy import getfilelist\r\n\r\nSCOPES = ['https://www.googleapis.com/auth/drive']\r\nSERVICE_ACCOUNT_FILE = 'service-account-credentials.json'\r\ncredentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)\r\n\r\nresource = {\r\n    \"service_account\": credentials,\r\n    \"id\": \"### Folder ID ###\",\r\n    \"fields\": \"files(name,id)\",\r\n}\r\nres = getfilelist.GetFileList(resource)  # or r = getfilelist.GetFolderTree(resource)\r\nprint(res)\r\n```\r\n\r\n### Note\r\n\r\n- You can modify the property of `fields`. When this is not used, the default fields are used.\r\n\r\n# Values\r\n\r\n![](images/downloadFolder_sample.png)\r\n\r\nAs a sample, when the values are retrieved from above structure, the results of `GetFolderTree()` becomes as follows.\r\n\r\n## Values retrieved by GetFolderTree()\r\n\r\n```python\r\nres = getfilelist.GetFolderTree(resource)\r\nprint(res)\r\n```\r\n\r\n```json\r\n{\r\n  \"id\": [\r\n    [\"folderIdOfsampleFolder1\"],\r\n    [\"folderIdOfsampleFolder1\", \"folderIdOfsampleFolder_2a\"],\r\n    [\"folderIdOfsampleFolder1\", \"folderIdOfsampleFolder_2b\"],\r\n    [\r\n      \"folderIdOfsampleFolder1\",\r\n      \"folderIdOfsampleFolder_2a\",\r\n      \"folderIdOfsampleFolder_2a_3a\"\r\n    ],\r\n    [\r\n      \"folderIdOfsampleFolder1\",\r\n      \"folderIdOfsampleFolder_2b\",\r\n      \"folderIdOfsampleFolder_2b_3a\"\r\n    ],\r\n    [\r\n      \"folderIdOfsampleFolder1\",\r\n      \"folderIdOfsampleFolder_2b\",\r\n      \"folderIdOfsampleFolder_2b_3b\"\r\n    ],\r\n    [\r\n      \"folderIdOfsampleFolder1\",\r\n      \"folderIdOfsampleFolder_2b\",\r\n      \"folderIdOfsampleFolder_2b_3b\",\r\n      \"folderIdOfsampleFolder_2b_3b_4a\"\r\n    ]\r\n  ],\r\n  \"names\": [\r\n    \"sampleFolder1\",\r\n    \"sampleFolder_2a\",\r\n    \"sampleFolder_2b\",\r\n    \"sampleFolder_2a_3a\",\r\n    \"sampleFolder_2b_3a\",\r\n    \"sampleFolder_2b_3b\",\r\n    \"sampleFolder_2b_3b_4a\"\r\n  ],\r\n  \"folders\": [\r\n    \"folderIdOfsampleFolder1\",\r\n    \"folderIdOfsampleFolder_2a\",\r\n    \"folderIdOfsampleFolder_2b\",\r\n    \"folderIdOfsampleFolder_2a_3a\",\r\n    \"folderIdOfsampleFolder_2b_3a\",\r\n    \"folderIdOfsampleFolder_2b_3b\",\r\n    \"folderIdOfsampleFolder_2b_3b_4a\"\r\n  ]\r\n}\r\n```\r\n\r\n## Values retrieved by Do()\r\n\r\n```python\r\nres = getfilelist.GetFileList(resource)\r\nprint(res)\r\n```\r\n\r\n```json\r\n{\r\n  \"searchedFolder\": {\r\n    \"id\": \"###\",\r\n    \"name\": \"sampleFolder1\",\r\n    \"mimeType\": \"application/vnd.google-apps.folder\",\r\n    \"parents\": [\"###\"],\r\n    \"createdTime\": \"2000-01-01T01:23:45.000Z\",\r\n    \"modifiedTime\": \"2000-01-01T01:23:45.000Z\",\r\n    \"webViewLink\": \"https://drive.google.com/drive/folders/###\",\r\n    \"owners\": [\r\n      { \"displayName\": \"###\", \"permissionId\": \"###\", \"emailAddress\": \"###\" }\r\n    ],\r\n    \"shared\": true\r\n  },\r\n  \"folderTree\": {\r\n    \"id\": [\r\n      [\"folderIdOfsampleFolder1\"],\r\n      [\"folderIdOfsampleFolder1\", \"folderIdOfsampleFolder_2a\"],\r\n      [\"folderIdOfsampleFolder1\", \"folderIdOfsampleFolder_2b\"],\r\n      [\r\n        \"folderIdOfsampleFolder1\",\r\n        \"folderIdOfsampleFolder_2a\",\r\n        \"folderIdOfsampleFolder_2a_3a\"\r\n      ],\r\n      [\r\n        \"folderIdOfsampleFolder1\",\r\n        \"folderIdOfsampleFolder_2b\",\r\n        \"folderIdOfsampleFolder_2b_3a\"\r\n      ],\r\n      [\r\n        \"folderIdOfsampleFolder1\",\r\n        \"folderIdOfsampleFolder_2b\",\r\n        \"folderIdOfsampleFolder_2b_3b\"\r\n      ],\r\n      [\r\n        \"folderIdOfsampleFolder1\",\r\n        \"folderIdOfsampleFolder_2b\",\r\n        \"folderIdOfsampleFolder_2b_3b\",\r\n        \"folderIdOfsampleFolder_2b_3b_4a\"\r\n      ]\r\n    ],\r\n    \"names\": [\r\n      \"sampleFolder1\",\r\n      \"sampleFolder_2a\",\r\n      \"sampleFolder_2b\",\r\n      \"sampleFolder_2a_3a\",\r\n      \"sampleFolder_2b_3a\",\r\n      \"sampleFolder_2b_3b\",\r\n      \"sampleFolder_2b_3b_4a\"\r\n    ],\r\n    \"folders\": [\r\n      \"folderIdOfsampleFolder1\",\r\n      \"folderIdOfsampleFolder_2a\",\r\n      \"folderIdOfsampleFolder_2b\",\r\n      \"folderIdOfsampleFolder_2a_3a\",\r\n      \"folderIdOfsampleFolder_2b_3a\",\r\n      \"folderIdOfsampleFolder_2b_3b\",\r\n      \"folderIdOfsampleFolder_2b_3b_4a\"\r\n    ]\r\n  },\r\n  \"fileList\": [\r\n    {\r\n      \"folderTree\": [\"folderIdOfsampleFolder1\"],\r\n      \"files\": [\r\n        {\r\n          \"name\": \"Spreadsheet1\",\r\n          \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\r\n        }\r\n      ]\r\n    },\r\n    {\r\n      \"folderTree\": [\"folderIdOfsampleFolder1\", \"folderIdOfsampleFolder_2a\"],\r\n      \"files\": [\r\n        {\r\n          \"name\": \"Spreadsheet2\",\r\n          \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\r\n        }\r\n      ]\r\n    },\r\n    {\r\n      \"folderTree\": [\"folderIdOfsampleFolder1\", \"folderIdOfsampleFolder_2b\"],\r\n      \"files\": [\r\n        {\r\n          \"name\": \"Spreadsheet4\",\r\n          \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\r\n        }\r\n      ]\r\n    },\r\n    {\r\n      \"folderTree\": [\r\n        \"folderIdOfsampleFolder1\",\r\n        \"folderIdOfsampleFolder_2a\",\r\n        \"folderIdOfsampleFolder_2a_3a\"\r\n      ],\r\n      \"files\": null\r\n    },\r\n    {\r\n      \"folderTree\": [\r\n        \"folderIdOfsampleFolder1\",\r\n        \"folderIdOfsampleFolder_2b\",\r\n        \"folderIdOfsampleFolder_2b_3a\"\r\n      ],\r\n      \"files\": [\r\n        {\r\n          \"name\": \"Spreadsheet3\",\r\n          \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\r\n        }\r\n      ]\r\n    },\r\n    {\r\n      \"folderTree\": [\r\n        \"folderIdOfsampleFolder1\",\r\n        \"folderIdOfsampleFolder_2b\",\r\n        \"folderIdOfsampleFolder_2b_3b\"\r\n      ],\r\n      \"files\": null\r\n    },\r\n    {\r\n      \"folderTree\": [\r\n        \"folderIdOfsampleFolder1\",\r\n        \"folderIdOfsampleFolder_2b\",\r\n        \"folderIdOfsampleFolder_2b_3b\",\r\n        \"folderIdOfsampleFolder_2b_3b_4a\"\r\n      ],\r\n      \"files\": [\r\n        {\r\n          \"name\": \"Document1\",\r\n          \"mimeType\": \"application/vnd.google-apps.document\"\r\n        },\r\n        {\r\n          \"name\": \"image1.png\",\r\n          \"mimeType\": \"image/png\"\r\n        },\r\n        {\r\n          \"name\": \"Slides1\",\r\n          \"mimeType\": \"application/vnd.google-apps.presentation\"\r\n        },\r\n        {\r\n          \"name\": \"Spreadsheet5\",\r\n          \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\r\n        },\r\n        {\r\n          \"name\": \"StandaloneProject1\",\r\n          \"mimeType\": \"application/vnd.google-apps.script\"\r\n        },\r\n        {\r\n          \"name\": \"Test1.txt\",\r\n          \"mimeType\": \"text/plain\"\r\n        }\r\n      ]\r\n    }\r\n  ],\r\n  \"totalNumberOfFiles\": 10,\r\n  \"totalNumberOfFolders\": 7\r\n}\r\n```\r\n\r\n# For other languages\r\n\r\nAs the libraries \"GetFileList\" for other languages, there are following libraries.\r\n\r\n- Golang: [https://github.com/tanaikech/go-getfilelist](https://github.com/tanaikech/go-getfilelist)\r\n- Google Apps Script: [https://github.com/tanaikech/FilesApp](https://github.com/tanaikech/FilesApp)\r\n- Javascript: [https://github.com/tanaikech/GetFileList_js](https://github.com/tanaikech/GetFileList_js)\r\n- Node.js: [https://github.com/tanaikech/node-getfilelist](https://github.com/tanaikech/node-getfilelist)\r\n- Python: [https://github.com/tanaikech/getfilelistpy](https://github.com/tanaikech/getfilelistpy)\r\n\r\n---\r\n\r\n\u003ca name=\"licence\"\u003e\u003c/a\u003e\r\n\r\n# Licence\r\n\r\n[MIT](LICENCE)\r\n\r\n\u003ca name=\"author\"\u003e\u003c/a\u003e\r\n\r\n# Author\r\n\r\n[Tanaike](https://tanaikech.github.io/about/)\r\n\r\nIf you have any questions and commissions for me, feel free to tell me.\r\n\r\n\u003ca name=\"Update_History\"\u003e\u003c/a\u003e\r\n\r\n# Update History\r\n\r\n- v1.0.0 (November 17, 2018)\r\n\r\n  1. Initial release.\r\n\r\n- v1.0.3 (July 16, 2019)\r\n\r\n  1. Markdown format was used to the readme file at [https://pypi.org/project/getfilelistpy/](https://pypi.org/project/getfilelistpy/).\r\n\r\n- v1.0.4 (August 23, 2019)\r\n\r\n  1. For OAuth2, `oauth2client` and `google_auth_oauthlib` got to be able to be used. About the sample script for `google_auth_oauthlib`, please see [this](#googleauthoauthlibsample).\r\n\r\n- v1.0.5 (May 15, 2020)\r\n\r\n  1. Shared drive got to be able to be used. The file list can be retrieved from both your Google Drive and the shared drive.\r\n\r\n     - For example, when the folder ID in the shared Drive is used `id` of `resource`, you can retrieve the file list from the folder in the shared Drive.\r\n\r\n- v1.0.6 (June 1, 2020)\r\n\r\n  1. When the file is retrieved from the shared drive, the parameter was not completed. This bug was removed.\r\n\r\n- v1.0.7 (August 11, 2020)\r\n\r\n  1. [Pull request](https://github.com/tanaikech/getfilelistpy/pull/4) was reflected.\r\n\r\n[TOP](#top)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanaikech%2Fgetfilelistpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanaikech%2Fgetfilelistpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanaikech%2Fgetfilelistpy/lists"}