Description:
- Interact with data in box.com
Resources:
Environment variables
Section titled “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
import fsspecfrom boxsdk import JWTAuthLoad your credentials
Section titled “Load your credentials”import os
import fsspecfrom 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 IDFor simple file access, you can use fsspec.open
Section titled “For simple file access, you can use fsspec.open”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
Section titled “For more control, you can use fsspec.filesystem”from fsspec import filesystem
fs = fsspec.filesystem('box', oauth=oauth)
# Create new directoryfs.mkdir("Documents")# # List directory contentsfs.ls('Documents')# Print file contentsfs.cat('Documents/test_file.txt/test_file_2.txt')# Note: touch won't work as it hasn't been implemented by boxfsfs.touch('Documents/test_file.txt')ganymede is made by Eugo