DropboxDrive Fs
Description:
- Interact with data in dropbox.com
Resources:
- [GitHub] https://github.com/fsspec/dropboxdrivefs
- [Dropbox Docs] https://dropbox.tech/developers/generate-an-access-token-for-your-own-account
- [Dropbox Docs] https://www.dropbox.com/developers/documentation?_tk=pilot_lp&_ad=topbar1&_camp=docs
- [Dropbox Docs] https://www.dropbox.com/developers
- [GitHub Examples] https://github.com/fsspec/dropboxdrivefs/blob/master/Example.ipynb
Environment variables
Section titled “Environment variables”This notebook reads its settings from environment variables. Set them before starting Jupyter:
DROPBOX_ACCESS_TOKEN: a Dropbox OAuth2 access token (seeauthentication.ipynb)
Example 1
Section titled “Example 1”Get info about a folder using DropboxDriveFileSystem
import os
import dropboxdrivefs as dbx
dropbox_access_token = os.environ["DROPBOX_ACCESS_TOKEN"]fs = dbx.DropboxDriveFileSystem(token=dropbox_access_token)fs.info("/example_folder")Example 2
Section titled “Example 2”Create a folder
fs = dbx.DropboxDriveFileSystem(token=dropbox_access_token)fs.mkdir("/Data/test_dropbox")Example 3
Section titled “Example 3”Upload a file
fs = dbx.DropboxDriveFileSystem(token=dropbox_access_token)from pathlib import Path
tmp_path = "/tmp/ganymede_demo"p = Path(tmp_path).mkdir(exist_ok=True)
with open(f"{tmp_path}/test1.txt", "w") as f: f.write("Hello")
fs.put_file(f"{tmp_path}/test1.txt", "/Data/test_dropbox/text1.txt")Example 4
Section titled “Example 4”Download a file
fs = dbx.DropboxDriveFileSystem(token=dropbox_access_token)from pathlib import Path
tmp_path = "/tmp/ganymede_demo"p = Path(tmp_path).mkdir(exist_ok=True)
remote_fp = "/Data/test_dropbox/text1.txt"local_fp = f"{tmp_path}/testing.txt"fs.download(remote_fp, local_fp)Example 5
Section titled “Example 5”List all files before removing the folder online
items = fs.ls("/Data/test_dropbox")for item in items: print(item["name"])
print("\nAvailable info for folder type:")print(list(items[0].keys()))
print("\nAvailable info for file type:")print(list(items[-1].keys()))ganymede is made by Eugo