b2sdk.transfer.outbound.upload_source

class b2sdk.transfer.outbound.upload_source.UploadMode(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Mode of file uploads

FULL = 1

always upload the whole file

INCREMENTAL = 2

use incremental uploads when possible

class b2sdk.transfer.outbound.upload_source.AbstractUploadSource[source]

Bases: OutboundTransferSource

The source of data for uploading to b2.

abstract get_content_sha1()[source]

Returns a 40-character string containing the hex SHA1 checksum of the data in the file.

Return type:

Optional[NewType(Sha1HexDigest, str)]

abstract open()[source]

Returns a binary file-like object from which the data can be read.

Return type:

IOBase

is_upload()[source]

Returns True if outbound source is an upload source.

Return type:

bool

is_copy()[source]

Returns True if outbound source is a copy source.

Return type:

bool

is_sha1_known()[source]

Returns information whether SHA1 of the source is currently available. Note that negative result doesn’t mean that SHA1 is not available. Calling get_content_sha1 can still provide a valid digest.

Return type:

bool

class b2sdk.transfer.outbound.upload_source.UploadSourceBytes(data_bytes, content_sha1=None)[source]

Bases: AbstractUploadSource

Parameters:
__init__(data_bytes, content_sha1=None)[source]

Initialize upload source using given bytes.

Parameters:
get_content_length()[source]

Returns the number of bytes of data in the file.

Return type:

int

get_content_sha1()[source]

Returns a 40-character string containing the hex SHA1 checksum of the data in the file.

Return type:

Optional[NewType(Sha1HexDigest, str)]

open()[source]

Returns a binary file-like object from which the data can be read.

is_sha1_known()[source]

Returns information whether SHA1 of the source is currently available. Note that negative result doesn’t mean that SHA1 is not available. Calling get_content_sha1 can still provide a valid digest.

Return type:

bool

class b2sdk.transfer.outbound.upload_source.UploadSourceLocalFileBase(local_path, content_sha1=None)[source]

Bases: AbstractUploadSource

Parameters:
__init__(local_path, content_sha1=None)[source]

Initialize upload source using provided path.

Parameters:
  • local_path (PathLike | str) – Any path-like object that points to a file to be uploaded.

  • content_sha1 (Optional[NewType(Sha1HexDigest, str)]) – SHA1 hexdigest of the data, or None.

check_path_and_get_size()[source]
Return type:

None

get_content_length()[source]

Returns the number of bytes of data in the file.

Return type:

int

get_content_sha1()[source]

Returns a 40-character string containing the hex SHA1 checksum of the data in the file.

Return type:

Optional[NewType(Sha1HexDigest, str)]

open()[source]

Returns a binary file-like object from which the data can be read.

is_sha1_known()[source]

Returns information whether SHA1 of the source is currently available. Note that negative result doesn’t mean that SHA1 is not available. Calling get_content_sha1 can still provide a valid digest.

Return type:

bool

class b2sdk.transfer.outbound.upload_source.UploadSourceLocalFileRange(local_path, content_sha1=None, offset=0, length=None)[source]

Bases: UploadSourceLocalFileBase

Parameters:
__init__(local_path, content_sha1=None, offset=0, length=None)[source]

Initialize upload source using provided path.

Parameters:
  • local_path (PathLike | str) – Any path-like object that points to a file to be uploaded.

  • content_sha1 (Optional[NewType(Sha1HexDigest, str)]) – SHA1 hexdigest of the data, or None.

  • offset (int) – Position in the file where upload should start from.

  • length (Optional[int]) – Amount of data to be uploaded. If None, length of the remainder of the file is taken.

open()[source]

Returns a binary file-like object from which the data can be read.

class b2sdk.transfer.outbound.upload_source.UploadSourceLocalFile(local_path, content_sha1=None)[source]

Bases: UploadSourceLocalFileBase

Parameters:
get_incremental_sources(file_version, min_part_size=None)[source]

Split the upload into a copy and upload source constructing an incremental upload

This will return a list of upload sources. If the upload cannot split, the method will return [self].

Parameters:
  • file_version (BaseFileVersion) –

  • min_part_size (Optional[int]) –

Return type:

list[OutboundTransferSource]

class b2sdk.transfer.outbound.upload_source.UploadSourceStream(stream_opener, stream_length=None, stream_sha1=None)[source]

Bases: AbstractUploadSource

Parameters:
__init__(stream_opener, stream_length=None, stream_sha1=None)[source]

Initialize upload source using arbitrary function.

Parameters:
  • stream_opener (Callable[[], IOBase]) – A function that opens a stream for uploading.

  • stream_length (Optional[int]) – Length of the stream. If None, data will be calculated from the stream the first time it’s required.

  • stream_sha1 (Optional[NewType(Sha1HexDigest, str)]) – SHA1 of the stream. If None, data will be calculated from the stream the first time it’s required.

get_content_length()[source]

Returns the number of bytes of data in the file.

Return type:

int

get_content_sha1()[source]

Returns a 40-character string containing the hex SHA1 checksum of the data in the file.

Return type:

Optional[NewType(Sha1HexDigest, str)]

open()[source]

Returns a binary file-like object from which the data can be read.

is_sha1_known()[source]

Returns information whether SHA1 of the source is currently available. Note that negative result doesn’t mean that SHA1 is not available. Calling get_content_sha1 can still provide a valid digest.

Return type:

bool

class b2sdk.transfer.outbound.upload_source.UploadSourceStreamRange(stream_opener, offset=0, stream_length=None, stream_sha1=None)[source]

Bases: UploadSourceStream

Parameters:
__init__(stream_opener, offset=0, stream_length=None, stream_sha1=None)[source]

Initialize upload source using arbitrary function.

Parameters:
  • stream_opener (Callable[[], IOBase]) – A function that opens a stream for uploading.

  • offset (int) – Offset from which stream should be uploaded.

  • stream_length (Optional[int]) – Length of the stream. If None, data will be calculated from the stream the first time it’s required.

  • stream_sha1 (Optional[NewType(Sha1HexDigest, str)]) – SHA1 of the stream. If None, data will be calculated from the stream the first time it’s required.

open()[source]

Returns a binary file-like object from which the data can be read.