API

bsync.cli

bsync

Syncs the contents of local folder to your Box account

SOURCE_FOLDER is the path of an existing local folder. Additional, optional PATHS can be added as a glob expression after the folder.

BOX_FOLDER_ID is the ID for the folder in Box where you want the files sent

Example:

bsync -s 12345.json -l DEBUG images::*.jpg 123456789

bsync [OPTIONS] SOURCE_FOLDER[::PATHS] BOX_FOLDER_ID

Options

--version

Show the version and exit.

-s, --settings <settings>
-o, --output <output>

File to write created items as CSV report

-c, --concurrency <concurrency>

Number of threads used to access the Box API using asyncio. The default is the number of CPUs available on your system.

-l, --log-level <log_level>

Log level

Options

critical | fatal | error | warn | warning | info | debug

--log-file <log_file>

Log file

-i, --ipdb

Drop into ipdb shell on error

Arguments

SOURCE_FOLDER[::PATHS]

Required argument

BOX_FOLDER_ID

Required argument

Environment variables

SOURCE_FOLDER

Provide a default for SOURCE_FOLDER[::PATHS]

BOX_FOLDER_ID

Provide a default for BOX_FOLDER_ID

BOX_SETTINGS_FILE

Provide a default for -s

bsync.api

class bsync.api.BoxAPI(logger, settings)[source]

Bases: object

Wraps boxsdk to create a client and perform actions, logging results

property client

Gets a boxsdk.Client instance from the JSON settings file using JWT

create_folder(parent_id, name)[source]

Creates a subfolder in an existing Box folder

send_chunked(path, session_func)[source]

Uses the chunked upload API from Box to upload sequential segments of a file

update(file_id, fname)[source]

Updates the contents of a file and uploads it to an existing file on Box

upload(parent_id, fname)[source]

Uploads a file to the parent folder_id Handles large files by chunking

bsync.sync

class bsync.sync.BoxSync(api, logger, concurrency, box_folder_id, source_folder_paths)[source]

Bases: object

Syncs the parent folder files to Box.

Compares current files, checks for any missing in Box or any changed locally, creates directory structure and finally uploads all files

get_box_paths(folder_id=None)[source]

Yields all paths recursively from the parent folder ID

get_parent(path)[source]

Returns the Box Folder object for the parent folder of path

has_changed(boxfile, path)[source]

Compares the file on Box with the path on disk Used to see if the local file has changed

output(filename)[source]

Writes output CSV of what files are synced and their destinations in Box

property parent_folder

Gets the parent folder in Box via API GET

prepare()[source]

Loads entries from local filesystem and Box Used to decide later which items to sync

run()[source]

Main method that finds local files and matching files on Box. Then syncs the folder/subfolder structure and finally syncs any files to Box from the local machine

async sync_files()[source]

Uploads the new or updated files to Box.com Folder structure must be created before running

sync_folders()[source]

Creates the subfolders in Box.com to match local filesystem Runs before new files are updated/uploaded

to_path(item)[source]

Converts a Box File/Folder to a filepath from the parent folder

bsync.log

bsync.log.get_logger(log_level=None, log_file=None)[source]

Configures a logger w/ file/stream handler from settings