Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
This is a python library to retrieve the file list with the folder tree from the specific folder of Google Drive.
This is a python library to retrieve the file list with the folder tree from the specific folder of own Google Drive and shared Drives.
When 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.
$ pip install getfilelistpy
You can also check this library at https://pypi.org/project/getfilelistpy/.
Method | Explanation |
---|---|
GetFolderTree(object) | Retrieve only folder structure from a folder |
GetFileList(object) | Retrieve file list with folder structure from a folder |
There are 3 patterns for using this library.
This is a sample script using API key. When you want to retrieve the API key, please do the following flow.
from getfilelistpy import getfilelist
resource = {
"api_key": "#####",
"id": "### Folder ID ###",
"fields": "files(name,id)",
}
res = getfilelist.GetFileList(resource) # or r = getfilelist.GetFolderTree(resource)
print(res)
fields
. When this is not used, the default fields are used.Document of OAuth2 is here.
In this sample script for oauth2client
.
from httplib2 import Http
from oauth2client import file, client, tools
from getfilelistpy import getfilelist
SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
resource = {
"oauth2": creds.authorize(Http()),
"id": "### Folder ID ###",
"fields": "files(name,id)",
}
res = getfilelist.GetFileList(resource) # or r = getfilelist.GetFolderTree(resource)
print(res)
In this sample script for google_auth_oauthlib
, the process of OAuth2 uses the quickstart of Google. Please check this.
import pickle
import os.path
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from getfilelistpy import getfilelist
SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
creds = None
creFile = 'token.pickle'
if os.path.exists(creFile):
with open(creFile, 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'client_secret.json', SCOPES)
creds = flow.run_local_server()
with open(creFile, 'wb') as token:
pickle.dump(creds, token)
resource = {
"oauth2": creds,
"id": "### Folder ID ###",
"fields": "files(name,id)",
}
res = getfilelist.GetFileList(resource) # or r = getfilelist.GetFolderTree(resource)
print(res)
fields
. When this is not used, the default fields are used.Document of Service account is here.
from google.oauth2 import service_account
from getfilelistpy import getfilelist
SCOPES = ['https://www.googleapis.com/auth/drive']
SERVICE_ACCOUNT_FILE = 'service-account-credentials.json'
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
resource = {
"service_account": credentials,
"id": "### Folder ID ###",
"fields": "files(name,id)",
}
res = getfilelist.GetFileList(resource) # or r = getfilelist.GetFolderTree(resource)
print(res)
fields
. When this is not used, the default fields are used.As a sample, when the values are retrieved from above structure, the results of GetFolderTree()
becomes as follows.
res = getfilelist.GetFolderTree(resource)
print(res)
{
"id": [
["folderIdOfsampleFolder1"],
["folderIdOfsampleFolder1", "folderIdOfsampleFolder_2a"],
["folderIdOfsampleFolder1", "folderIdOfsampleFolder_2b"],
[
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2a",
"folderIdOfsampleFolder_2a_3a"
],
[
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2b_3a"
],
[
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2b_3b"
],
[
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2b_3b",
"folderIdOfsampleFolder_2b_3b_4a"
]
],
"names": [
"sampleFolder1",
"sampleFolder_2a",
"sampleFolder_2b",
"sampleFolder_2a_3a",
"sampleFolder_2b_3a",
"sampleFolder_2b_3b",
"sampleFolder_2b_3b_4a"
],
"folders": [
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2a",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2a_3a",
"folderIdOfsampleFolder_2b_3a",
"folderIdOfsampleFolder_2b_3b",
"folderIdOfsampleFolder_2b_3b_4a"
]
}
res = getfilelist.GetFileList(resource)
print(res)
{
"searchedFolder": {
"id": "###",
"name": "sampleFolder1",
"mimeType": "application/vnd.google-apps.folder",
"parents": ["###"],
"createdTime": "2000-01-01T01:23:45.000Z",
"modifiedTime": "2000-01-01T01:23:45.000Z",
"webViewLink": "https://drive.google.com/drive/folders/###",
"owners": [
{ "displayName": "###", "permissionId": "###", "emailAddress": "###" }
],
"shared": true
},
"folderTree": {
"id": [
["folderIdOfsampleFolder1"],
["folderIdOfsampleFolder1", "folderIdOfsampleFolder_2a"],
["folderIdOfsampleFolder1", "folderIdOfsampleFolder_2b"],
[
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2a",
"folderIdOfsampleFolder_2a_3a"
],
[
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2b_3a"
],
[
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2b_3b"
],
[
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2b_3b",
"folderIdOfsampleFolder_2b_3b_4a"
]
],
"names": [
"sampleFolder1",
"sampleFolder_2a",
"sampleFolder_2b",
"sampleFolder_2a_3a",
"sampleFolder_2b_3a",
"sampleFolder_2b_3b",
"sampleFolder_2b_3b_4a"
],
"folders": [
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2a",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2a_3a",
"folderIdOfsampleFolder_2b_3a",
"folderIdOfsampleFolder_2b_3b",
"folderIdOfsampleFolder_2b_3b_4a"
]
},
"fileList": [
{
"folderTree": ["folderIdOfsampleFolder1"],
"files": [
{
"name": "Spreadsheet1",
"mimeType": "application/vnd.google-apps.spreadsheet"
}
]
},
{
"folderTree": ["folderIdOfsampleFolder1", "folderIdOfsampleFolder_2a"],
"files": [
{
"name": "Spreadsheet2",
"mimeType": "application/vnd.google-apps.spreadsheet"
}
]
},
{
"folderTree": ["folderIdOfsampleFolder1", "folderIdOfsampleFolder_2b"],
"files": [
{
"name": "Spreadsheet4",
"mimeType": "application/vnd.google-apps.spreadsheet"
}
]
},
{
"folderTree": [
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2a",
"folderIdOfsampleFolder_2a_3a"
],
"files": null
},
{
"folderTree": [
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2b_3a"
],
"files": [
{
"name": "Spreadsheet3",
"mimeType": "application/vnd.google-apps.spreadsheet"
}
]
},
{
"folderTree": [
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2b_3b"
],
"files": null
},
{
"folderTree": [
"folderIdOfsampleFolder1",
"folderIdOfsampleFolder_2b",
"folderIdOfsampleFolder_2b_3b",
"folderIdOfsampleFolder_2b_3b_4a"
],
"files": [
{
"name": "Document1",
"mimeType": "application/vnd.google-apps.document"
},
{
"name": "image1.png",
"mimeType": "image/png"
},
{
"name": "Slides1",
"mimeType": "application/vnd.google-apps.presentation"
},
{
"name": "Spreadsheet5",
"mimeType": "application/vnd.google-apps.spreadsheet"
},
{
"name": "StandaloneProject1",
"mimeType": "application/vnd.google-apps.script"
},
{
"name": "Test1.txt",
"mimeType": "text/plain"
}
]
}
],
"totalNumberOfFiles": 10,
"totalNumberOfFolders": 7
}
As the libraries "GetFileList" for other languages, there are following libraries.
If you have any questions and commissions for me, feel free to tell me.
v1.0.0 (November 17, 2018)
v1.0.3 (July 16, 2019)
v1.0.4 (August 23, 2019)
oauth2client
and google_auth_oauthlib
got to be able to be used. About the sample script for google_auth_oauthlib
, please see this.v1.0.5 (May 15, 2020)
Shared drive got to be able to be used. The file list can be retrieved from both your Google Drive and the shared drive.
id
of resource
, you can retrieve the file list from the folder in the shared Drive.v1.0.6 (June 1, 2020)
FAQs
This is a python library to retrieve the file list with the folder tree from the specific folder of Google Drive.
We found that getfilelistpy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.