> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# DropboxDrive Fs

> DropboxDrive Fs: Interact with data in dropbox.com. A Python demo notebook from ganymede.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/data_storage/filesystems/dropbox/dropboxdrivefs/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/data_storage/filesystems/dropbox/dropboxdrivefs/dropboxdrivefs.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/data_storage/filesystems/dropbox/dropboxdrivefs.ipynb)

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

This notebook reads its settings from environment variables. Set them before starting Jupyter:

- `DROPBOX_ACCESS_TOKEN`: a Dropbox OAuth2 access token (see `authentication.ipynb`)

## Example 1

Get info about a folder using `DropboxDriveFileSystem`

```python
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

Create a folder

```python
fs = dbx.DropboxDriveFileSystem(token=dropbox_access_token)
fs.mkdir("/Data/test_dropbox")
```

## Example 3

Upload a file

```python
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

Download a file

```python
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

List all files before removing the folder online

```python
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()))
```
