Box

Class that allows for access to the box API and methods to directly upload files. If you wish to use the Box API you should view the install.

Authentication

In order for the Box API to work, it needs to get a user specific access and refresh token. Box provides access tokens to users which are a session key. They remain active for one hour at which time they must be refreshed using the refresh token. Once a new access and refresh token has been given, the old one will no longer work.

The tokens can be provided in three ways. First, you can run Box(...).connect() which will start a flask webserver. You can then proceed to 127.0.0.1:5000 and log in with your Box username and password. This is done securely through Box and you username and password cannot be extracted. Second, you can insert the access and refresh token in the config file. Then the Box class will use these tokens. The final way to provide the tokens is by directly passign them to Box(...).connect(access_token=<your access token>, refresh_token=<your refresh token>).

On a server, where you have no access to a web browser, you will need to get the tokens using a computer which has a web browser. You can then place those tokens in the config file or directly pass them to the connect() method.

class dapt.box.Box(*args, **kwargs)

Class which allows for connection to box API. You must either provide a Config object or client_id and client_secret.

Keyword Arguments:
 
  • config (Config) – A Config object which contains the client_id and client_secret.
  • client_id (str) – The Box client ID.
  • client_secret (str) – The Box client secret.
connect(access_token=None, refresh_token=None)

Tries to connect to box using arguments provided in Config and starts server for authorization if not.

Parameters:
  • access_token (str) – Optional argument that allows DAPT to connect to box without going through web authentication (assuming refresh_token is given and not expired).
  • refresh_token (str) – Optional argument that allows DAPT to connect to box without going through web authentication (assuming access_token is given and not expired).
Returns:

Box client if successful

updateTokens(access_token)

Refresh the access and refresh token given a valid access token

Parameters:access_token (string) – box access token to be refreshed
Returns:Box client
uploadFile(folderID, path, name)

Upload a file to box using the current client

Parameters:
  • folderID (string) – the box folder ID that the file should be added to (found in URL)
  • path (string) – the path to the file on your local machine
  • file (string) – the name of the file you wish to upload