From the Client ID and Client Secret from Box, get the Access Token and the Refresh Token.
>>> flow = BoxAuthenticateFlow('my_id', 'my_secret')
>>> url = flow.get_authorization_url()
...
...
>>> access_token, refresh_token = flow.get_access_tokens('generated_auth_code')
From the authorization code, get the “access token” and the “refresh token” from Box.
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Get the url used to get an authorization code.
Manage files and folder from Box.
When you instanciate this class you have to provide at least the Refresh Token (found with BoxAuthenticateFlow). If the Access Token is not provided a request will be made to Box to get a new one (and a new Refresh Token will be generated).
The Access Token expires every hour. When you use this class with an Access Token expired, a new one will be requested automatically.
Use the “tokens_changed” callback to backup the Access Token and the Refresh Token each time they change. If you do not backup them, you will have to follow the authenticate flow again (with BoxAuthenticateFlow).
>>> def tokens_changed(refresh_token, access_token):
... save_to_file(refresh_token, access_token)
...
>>> box = BoxSession('my_id', 'my_secret', refresh_token, access_token, tokens_changed)
>>> print box.get_folder_info(0)
Upload a file chunk by chunk.
The whole file is never loaded in memory. Use this function for big file.
The callback(transferred, total) to let you know the upload progress. Upload can be cancelled if the callback raise an Exception.
>>> def progress_callback(transferred, total):
... print 'Uploaded %i bytes of %i' % (transferred, total, )
... if user_request_cancel:
... raise MyCustomCancelException()
name (str): Name of the file on your Box storage.
folder_id (int): ID of the folder where to upload the file.
file_path (str): Local path of the file to upload.
progress_callback (func): Function called each time a chunk is uploaded.
chunk_size (int): Size of chunks.
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Copy file to new destination
file_id (int): ID of the folder.
dest_folder_id (int): ID of parent folder you are copying to.
BoxError: An error response is returned from Box (status_code >= 400).
BoxError: 409 - Item with the same name already exists. In this case you will need download the file and upload a new version to your destination. (Box currently doesn’t have a method to copy a new verison.)
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Create a folder
If the folder exists, a BoxError will be raised.
folder_id (int): Name of the folder.
parent_folder_id (int): ID of the folder where to create the new one.
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Delete an existing file
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Delete an existing folder
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Download a file.
The whole file is never loaded in memory.
The callback(transferred, total) to let you know the download progress. Download can be cancelled if the callback raise an Exception.
>>> def progress_callback(transferred, total):
... print 'Downloaded %i bytes of %i' % (transferred, total, )
... if user_request_cancel:
... raise MyCustomCancelException()
file_id (int): ID of the file to download.
dest_file_path (str): Local path where to store the downloaded filed.
progress_callback (func): Function called each time a chunk is downloaded.
chunk_size (int): Size of chunks.
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Find a folder or a file ID from its name, inside a given folder.
name (str): Name of the folder or the file to find.
parent_folder_id (int): ID of the folder where to search.
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Get info on a file
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Get info on a folder
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Get files and folders inside a given folder
folder_id (int): Where to get files and folders info.
limit (int): The number of items to return.
offset (int): The item at which to begin the response.
fields_list (list): List of attributes to get. All attributes if None.
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Searches for files/folders
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Upload a file into a folder.
Use function for small file otherwise there is the chunk_upload_file() function
name (str): Name of the file on your Box storage.
folder_id (int): ID of the folder where to upload the file.
file_path (str): Local path of the file to upload.
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.
Upload a new version of a file into a folder.
Use function for small file otherwise there is the chunk_upload_file() function.
name (str): Name of the file on your Box storage.
folder_id (int): ID of the folder where to upload the file.
file_id (int): ID of the file to update.
file_path (str): Local path of the file to upload.
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: Any connection related problem.