Progress reporters

Note

Concrete classes described in this chapter implement methods defined in AbstractProgressListener

class b2sdk.v2.AbstractProgressListener(description='')[source]

Interface expected by B2Api upload and download methods to report on progress.

This interface just accepts the number of bytes transferred so far. Subclasses will need to know the total size if they want to report a percent done.

Parameters:

description (str) –

abstract set_total_bytes(total_byte_count)[source]

Always called before __enter__ to set the expected total number of bytes.

May be called more than once if an upload is retried.

Parameters:

total_byte_count (int) – expected total number of bytes

Return type:

None

abstract bytes_completed(byte_count)[source]

Report the given number of bytes that have been transferred so far. This is not a delta, it is the total number of bytes transferred so far.

Transfer can fail and restart from the beginning, so byte count can decrease between calls.

Parameters:

byte_count (int) – number of bytes have been transferred

Return type:

None

change_description(new_description)[source]

Ability to change the description after the listener is started.

Note: whether the change of description is allowed depends on the implementation. The safest option is to change the description before setting the total bytes.

Parameters:

new_description (str) – the new description to be used

Return type:

bool

Returns:

information whether the description was changed

close()[source]

Must be called when you’re done with the listener. In well-structured code, should be called only once.

Return type:

None

class b2sdk.v2.TqdmProgressListener(*args, **kwargs)[source]

Progress listener based on tqdm library.

This listener displays a nice progress bar, but requires tqdm package to be installed.

class b2sdk.v2.SimpleProgressListener(*args, **kwargs)[source]

Just a simple progress listener which prints info on a console.

class b2sdk.v2.DoNothingProgressListener(description='')[source]

This listener gives no output whatsoever.

Parameters:

description (str) –

class b2sdk.v2.ProgressListenerForTest(*args, **kwargs)[source]

Capture all the calls so they can be checked.

b2sdk.v2.make_progress_listener(description, quiet)[source]

Produce the best progress listener available for the given parameters.

Parameters:
  • description (str) – listener description

  • quiet (bool) – if True, do not output anything

Return type:

AbstractProgressListener

Returns:

a listener object