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

# Box Fs

> Box Fs: Interact with data in box.com. A Python demo notebook from ganymede.

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

Description:
- Interact with data in box.com

Resources:
- https://github.com/IBM/boxfs
- https://github.com/IBM/boxfs/blob/main/src/boxfs/boxfs.py

## Environment variables

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

- `BOX_JWT_CONFIG_PATH`: path to the JWT app config JSON downloaded from the Box developer console

```python
import fsspec
from boxsdk import JWTAuth
```

## Load your credentials

```python
import os

import fsspec
from boxsdk import JWTAuth

# The JWT app config JSON from the Box developer console holds clientID, clientSecret,
# publicKeyID, privateKey, passphrase and enterpriseID. Keep it outside the repository.
oauth = JWTAuth.from_settings_file(os.environ["BOX_JWT_CONFIG_PATH"])
root_id = "0" # root folder ID
```

## For simple file access, you can use `fsspec.open`

```python
with fsspec.open("box://Documents/test_file.txt", "wb", oauth=oauth, root_id=root_id) as f:
    f.write(b"This file was produced using boxfs")
```

## For more control, you can use `fsspec.filesystem`

```python
from fsspec import filesystem

fs = fsspec.filesystem('box', oauth=oauth)

# Create new directory
fs.mkdir("Documents")
```

```python
# # List directory contents
fs.ls('Documents')
```

```python
# Print file contents
fs.cat('Documents/test_file.txt/test_file_2.txt')
```

```python
# Note: touch won't work as it hasn't been implemented by boxfs
fs.touch('Documents/test_file.txt')
```
