Package: boxfs
boxfsImplementation of thefsspecprotocol forBoxcontent management, enabling you to
interface with files stored on Box using a file-system-like navigation.InstallationYou can installboxfsfromPyPI. Use the following
command:pipinstallboxfsTo use install the optionalupathdependency, use the following commandpipinstallboxfs[upath]ExampleimportfsspecfromboxsdkimportJWTAuthoauth=JWTAuth.from_settings_file("PATH/TO/JWT_CONFIGURATION.json")root_id="<ID-of-file-system-root>"### For simple file access, you can use `fsspec.open`withfsspec.open("box://Documents/test_file.txt","wb",oauth=oauth,root_id=root_id)asf:f.write("This file was produced using boxfs")### For more control, you can use `fsspec.filesystem`fs=fsspec.filesystem('box',oauth=oauth,root_id=root_id)# List directory contentsfs.ls("Documents")# Make new directoryfs.mkdir("Documents/Test Folder")# Remove a directoryfs.rmdir("Documents/Test Folder")# Open and write filewithfs.open("Documents/test_file.txt","wb")asf:f.write("This file was updated using boxfs")# Print file contentsfs.cat("Documents/test_file.txt")# Delete filefs.rm("Documents/test_file.txt")# If you installed with the `upath` extra, you can also use the universal-pathlib UPath# class.fromupathimportUPathpath=UPath("Documents",fs=fs)/"test_file.txt"path.read_text()Storage OptionsThe following storage options are accepted byfsspecwhen creating aBoxFileSystemobject:oauth: Box app OAuth2 configuration dictionary, e.g. loaded fromJWTAuth.from_settings_file, by default Noneclient: An already instantiated boxsdkClientobjectclient_type: Type ofClientclass to use when connecting to boxIfclientis provided, it is used for handling API calls. Otherwise, the file
system to instantiate a new client connection, of typeclient_type, using the
providedoauthconfiguration.root_id: Box ID (asstr) of folder where file system root is placed, by default
Noneroot_path: Path (asstr) to Box root folder, must be relative to user's root
(e.g. "All Files"). The client must have access to the application user's root
folder (i.e., it cannot be downscoped to a subfolder)If onlyroot_idis provided, theroot_pathis determined from API calls. If
onlyroot_pathis provided, theroot_idis determined from API calls. If
neither is provided, the application user's root folder is used.path_map: Mapping of paths to object ID strings, used to populate initial lookup
cache for quick directory navigationscopes: List of permissions to which the API token should be restricted. If None
(default), no restrictions are applied. If scopes are provided, the client
connection is (1) downscoped to use only the provided scopes, and
(2) restricted to the directory/subdirectories of the root folder.Creating a Box AppBefore you can useboxfs, you will need a Box application through which you can route
your API calls. To do so, you can follow the steps for"Setup with JWT"in the Box Developer documentation. The JWT configuration.jsonfile that
you generate will have to be stored locally and loaded usingJWTAuth.from_settings_file. You also have to add your application's
Service Account as a collaborator on the root folder of your choosing, or
you will only have access to the Box application's files.