Data classes

class b2sdk.v2.FileVersion(api, id_, file_name, size, content_type, content_sha1, file_info, upload_timestamp, account_id, bucket_id, action, content_md5, server_side_encryption, file_retention=FileRetentionSetting(None, None), legal_hold=LegalHold.UNSET, replication_status=None, cache_control=None)[source]

A structure which represents a version of a file (in B2 cloud).

Variables:
  • ~.id_ (str) – fileId

  • ~.file_name (str) – full file name (with path)

  • ~.size – size in bytes, can be None (unknown)

  • ~.content_type (str) – RFC 822 content type, for example "application/octet-stream"

  • ~.upload_timestamp – in milliseconds since epoch. Can be None (unknown).

  • ~.action (str) – "upload", "hide" or "delete"

Parameters:
cache_control
as_dict()[source]

represents the object as a dict which looks almost exactly like the raw api output for upload/list

ADVANCED_HEADERS_LIMIT = 2048
DEFAULT_HEADERS_LIMIT = 7000
account_id
action
api
bucket_id
property content_disposition: str | None
property content_encoding: str | None
property content_language: str | None
content_md5
content_sha1
content_sha1_verified
content_type
delete(bypass_governance=False)

Delete this file version. bypass_governance must be set to true if deleting a file version protected by Object Lock governance mode retention settings (unless its retention period expired)

Parameters:

bypass_governance (bool) –

Return type:

FileIdAndName

download(progress_listener=None, range_=None, encryption=None)[source]
Parameters:
Return type:

DownloadedFile

property expires: str | None
expires_parsed()[source]

Return the expiration date as a datetime object, or None if there is no expiration date. Raise ValueError if expires property is not a valid HTTP-date.

Return type:

Optional[datetime]

file_info
file_name
file_retention
get_content_sha1()

Get the file’s content SHA1 hex digest from the header or, if its absent, from the file info. If both are missing, return None.

Return type:

Optional[NewType(Sha1HexDigest, str)]

get_fresh_state()[source]

Fetch all the information about this file version and return a new FileVersion object. This method does NOT change the object it is called on.

Return type:

FileVersion

property has_large_header: bool

Determine whether FileVersion’s info fits header size limit defined by B2. This function makes sense only for “advanced” buckets, i.e. those which have Server-Side Encryption or File Lock enabled.

See https://www.backblaze.com/b2/docs/files.html#httpHeaderSizeLimit.

id_
legal_hold
mod_time_millis
replication_status
server_side_encryption
size
Parameters:

legal_hold (LegalHold) –

Return type:

BaseFileVersion

update_retention(file_retention, bypass_governance=False)
Parameters:
Return type:

BaseFileVersion

upload_timestamp
class b2sdk.v2.DownloadVersion(api, id_, file_name, size, content_type, content_sha1, file_info, upload_timestamp, server_side_encryption, range_, content_disposition, content_length, content_language, expires, cache_control, content_encoding, file_retention=FileRetentionSetting(None, None), legal_hold=LegalHold.UNSET, replication_status=None)[source]

A structure which represents metadata of an initialized download

Parameters:
range_
content_disposition
content_length
content_language
expires
cache_control
content_encoding
expires_parsed()[source]

Return the expiration date as a datetime object, or None if there is no expiration date. Raise ValueError if expires property is not a valid HTTP-date.

Return type:

Optional[datetime]

as_dict()[source]

represents the object as a dict which looks almost exactly like the raw api output for upload/list

Return type:

dict

api
content_sha1
content_sha1_verified
content_type
delete(bypass_governance=False)

Delete this file version. bypass_governance must be set to true if deleting a file version protected by Object Lock governance mode retention settings (unless its retention period expired)

Parameters:

bypass_governance (bool) –

Return type:

FileIdAndName

file_info
file_name
file_retention
get_content_sha1()

Get the file’s content SHA1 hex digest from the header or, if its absent, from the file info. If both are missing, return None.

Return type:

Optional[NewType(Sha1HexDigest, str)]

id_
legal_hold
mod_time_millis
replication_status
server_side_encryption
size
Parameters:

legal_hold (LegalHold) –

Return type:

BaseFileVersion

update_retention(file_retention, bypass_governance=False)
Parameters:
Return type:

BaseFileVersion

upload_timestamp
class b2sdk.v2.FileIdAndName(file_id, file_name)[source]

A structure which represents a B2 cloud file with just file_name and fileId attributes.

Used to return data from calls to b2_delete_file_version and b2_cancel_large_file.

Parameters:
  • file_id (str) –

  • file_name (str) –

classmethod from_cancel_or_delete_response(response)[source]
as_dict()[source]

represents the object as a dict which looks almost exactly like the raw api output for delete_file_version

__dict__ = mappingproxy({'__module__': 'b2sdk.file_version', '__doc__': '\n    A structure which represents a B2 cloud file with just `file_name` and `fileId` attributes.\n\n    Used to return data from calls to b2_delete_file_version and b2_cancel_large_file.\n    ', '__init__': <function FileIdAndName.__init__>, 'from_cancel_or_delete_response': <classmethod(<function FileIdAndName.from_cancel_or_delete_response>)>, 'as_dict': <function FileIdAndName.as_dict>, '__eq__': <function FileIdAndName.__eq__>, '__repr__': <function FileIdAndName.__repr__>, '__dict__': <attribute '__dict__' of 'FileIdAndName' objects>, '__weakref__': <attribute '__weakref__' of 'FileIdAndName' objects>, '__hash__': None, '__annotations__': {}})
class b2sdk.v2.UnfinishedLargeFile[source]

A structure which represents a version of a file (in B2 cloud).

Variables:
  • ~.file_id (str) – fileId

  • ~.file_name (str) – full file name (with path)

  • ~.account_id (str) – account ID

  • ~.bucket_id (str) – bucket ID

  • ~.content_type (str) – RFC 822 content type, for example "application/octet-stream"

  • ~.file_info (dict) – file info dict

class b2sdk.v2.Part(file_id, part_number, content_length, content_sha1)[source]

A structure which represents a part of a large file upload.

Variables:
  • ~.file_id (str) – fileId

  • ~.part_number (int) – part number, starting with 1

  • ~.content_length (str) – content length, in bytes

  • ~.content_sha1 (str) – checksum

class b2sdk.v2.Range(start, end)[source]

HTTP ranges use an inclusive index at the end.

__init__(start, end)[source]