b2sdk.progress – Progress

class b2sdk.progress.AbstractProgressListener[source]

Bases: object

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.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

abstract bytes_completed(byte_count)[source]

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

Parameters

byte_count (int) – number of bytes have been transferred

abstract close()[source]

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

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

class b2sdk.progress.AbstractStreamWithProgress(stream, progress_listener, offset=0)[source]

Bases: object

Wraps a file-like object and updates a ProgressListener as data is read / written. In the abstract class, read and write methods do not update the progress - child classes shall do it

__init__(stream, progress_listener, offset=0)[source]
Parameters
flush()[source]

Flush the stream

read(size=None)[source]

Read data from the stream

Parameters

size (int) – number of bytes to read

Returns

data read from the stream

seek(pos)[source]

Seek to a given position in the stream

Parameters

pos (int) – position in the stream

tell()[source]

Return current stream position

Return type

int

write(data)[source]

Write data to the stream

Parameters

data – a data to write to the stream

class b2sdk.progress.DoNothingProgressListener[source]

Bases: b2sdk.progress.AbstractProgressListener

This listener performs no any output

bytes_completed(byte_count)[source]

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

Parameters

byte_count (int) – number of bytes have been transferred

close()[source]

Perform clean up operations

set_total_bytes(total_byte_count)[source]

Set the expected total number of bytes.

Parameters

total_byte_count (int) – expected total number of bytes

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

Bases: b2sdk.progress.AbstractProgressListener

Captures all of the calls so they can be checked.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

bytes_completed(byte_count)[source]

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

Parameters

byte_count (int) – number of bytes have been transferred

close()[source]

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

get_calls()[source]
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

class b2sdk.progress.RangeOfInputStream(stream, offset, length)[source]

Bases: object

Wraps a file-like object (read only) and reads the selected range of the file.

__init__(stream, offset, length)[source]
Parameters
  • stream – a seekable stream

  • offset (int) – offset in the stream

  • length (int) – max number of bytes to read

read(size=None)[source]

Read data from the stream

Parameters

size (int) – number of bytes to read

Returns

data read from the stream

seek(pos)[source]

Seek to a given position in the stream

Parameters

pos (int) – position in the stream

class b2sdk.progress.ReadingStreamWithProgress(stream, progress_listener, offset=0)[source]

Bases: b2sdk.progress.AbstractStreamWithProgress

Wraps a file-like object, updates progress while reading

read(size=None)[source]

Read data from the stream

Parameters

size (int) – number of bytes to read

Returns

data read from the stream

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

Bases: b2sdk.progress.AbstractProgressListener

Just a simple progress listener which prints info on a console

__init__(description, *args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

bytes_completed(byte_count)[source]

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

Parameters

byte_count (int) – number of bytes have been transferred

close()[source]

Perform clean up operations

set_total_bytes(total_byte_count)[source]

Set the expected total number of bytes.

Parameters

total_byte_count (int) – expected total number of bytes

class b2sdk.progress.StreamWithHash(stream)[source]

Bases: object

Wraps a file-like object, calculates SHA1 while reading and appends hash at the end

__init__(stream)[source]
Parameters

stream – the stream to read from

Returns

None

hash_size()[source]

Calculate size of a hash string

Return type

int

read(size=None)[source]

Read data from the stream

Parameters

size (int) – number of bytes to read

Returns

data read from the stream

seek(pos)[source]

Seek to a given position in the stream

Parameters

pos (int) – position in the stream

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

Bases: b2sdk.progress.AbstractProgressListener

Progress listener based on tqdm library

__init__(description, *args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

bytes_completed(byte_count)[source]

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

Parameters

byte_count (int) – number of bytes have been transferred

close()[source]

Perform clean up operations

set_total_bytes(total_byte_count)[source]

Set the expected total number of bytes.

Parameters

total_byte_count (int) – expected total number of bytes

class b2sdk.progress.WritingStreamWithProgress(stream, progress_listener, offset=0)[source]

Bases: b2sdk.progress.AbstractStreamWithProgress

Wraps a file-like object, updates progress while writing

write(data)[source]

Write data to the stream

Parameters

data – a data to write to the stream

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

Returns a progress listener object depending on some conditions

Parameters
  • description (str) – listener description

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

Returns

a listener object