B2 Bucket¶
-
class
b2sdk.v1.
Bucket
[source]¶ -
FILE_VERSION_FACTORY
¶ alias of
b2sdk.v1.file_version.FileVersionInfoFactory
-
copy_file
(file_id, new_file_name, bytes_range=None, metadata_directive=None, content_type=None, file_info=None, destination_encryption: Optional[b2sdk.encryption.setting.EncryptionSetting] = None, source_encryption: Optional[b2sdk.encryption.setting.EncryptionSetting] = None, file_retention: Optional[b2sdk.file_lock.FileRetentionSetting] = None, legal_hold: Optional[b2sdk.file_lock.LegalHold] = None)[source]¶ Creates a new file in this bucket by (server-side) copying from an existing file.
- Parameters
file_id (str) – file ID of existing file
new_file_name (str) – file name of the new file
bytes_range (tuple[int,int],None) – start and end offsets (inclusive!), default is the entire file
metadata_directive (b2sdk.v1.MetadataDirectiveMode,None) – default is
b2sdk.v1.MetadataDirectiveMode.COPY
content_type (str,None) – content_type for the new file if metadata_directive is set to
b2sdk.v1.MetadataDirectiveMode.REPLACE
, default will copy the content_type of old filefile_info (dict,None) – file_info for the new file if metadata_directive is set to
b2sdk.v1.MetadataDirectiveMode.REPLACE
, default will copy the file_info of old filedestination_encryption (b2sdk.v1.EncryptionSetting) – encryption settings for the destination (
None
if unknown)source_encryption (b2sdk.v1.EncryptionSetting) – encryption settings for the source (
None
if unknown)file_retention (b2sdk.v1.FileRetentionSetting) – retention setting for the new file
legal_hold (bool) – legalHold setting for the new file
-
start_large_file
(file_name, content_type=None, file_info=None, file_retention: Optional[b2sdk.file_lock.FileRetentionSetting] = None, legal_hold: Optional[b2sdk.file_lock.LegalHold] = None)[source]¶ Start a large file transfer.
- Parameters
file_name (str) – a file name
content_type (str,None) – the MIME type, or
None
to accept the default based on file extension of the B2 file namefile_info (dict,None) – a file info to store with the file or
None
to not store anythingfile_retention (b2sdk.v1.FileRetentionSetting) – retention setting for the new file
legal_hold (bool) – legalHold setting for the new file
-
create_file
(write_intents, file_name, content_type=None, file_info=None, progress_listener=None, recommended_upload_part_size=None, continue_large_file_id=None, encryption: Optional[b2sdk.encryption.setting.EncryptionSetting] = None, file_retention: Optional[b2sdk.file_lock.FileRetentionSetting] = None, legal_hold: Optional[b2sdk.file_lock.LegalHold] = None)[source]¶ Creates a new file in this bucket using an iterable (list, tuple etc) of remote or local sources.
Source ranges can overlap and remote sources will be prioritized over local sources (when possible). For more information and usage examples please see Advanced usage patterns.
- Parameters
write_intents (list[b2sdk.v1.WriteIntent]) – list of write intents (remote or local sources)
new_file_name (str) – file name of the new file
content_type (str,None) – content_type for the new file, if
None
content_type would be automatically determined or it may be copied if it resolves as single part remote source copyfile_info (dict,None) – file_info for the new file, if
None
it will be set to empty dict or it may be copied if it resolves as single part remote source copyprogress_listener (b2sdk.v1.AbstractProgressListener,None) – a progress listener object to use, or
None
to not report progressrecommended_upload_part_size (int,None) – the recommended part size to use for uploading local sources or
None
to determine automatically, but remote sources would be copied with maximum possible part sizecontinue_large_file_id (str,None) – large file id that should be selected to resume file creation for multipart upload/copy,
None
for automatic search for this idencryption (b2sdk.v1.EncryptionSetting) – encryption settings (
None
if unknown)file_retention (b2sdk.v1.FileRetentionSetting) – file retention setting
legal_hold (bool) – legal hold setting
-
create_file_stream
(write_intents_iterator, file_name, content_type=None, file_info=None, progress_listener=None, recommended_upload_part_size=None, continue_large_file_id=None, encryption: Optional[b2sdk.encryption.setting.EncryptionSetting] = None, file_retention: Optional[b2sdk.file_lock.FileRetentionSetting] = None, legal_hold: Optional[b2sdk.file_lock.LegalHold] = None)[source]¶ Creates a new file in this bucket using a stream of multiple remote or local sources.
Source ranges can overlap and remote sources will be prioritized over local sources (when possible). For more information and usage examples please see Advanced usage patterns.
- Parameters
write_intents_iterator (iterator[b2sdk.v1.WriteIntent]) – iterator of write intents which are sorted ascending by
destination_offset
new_file_name (str) – file name of the new file
content_type (str,None) – content_type for the new file, if
None
content_type would be automatically determined or it may be copied if it resolves as single part remote source copyfile_info (dict,None) – file_info for the new file, if
None
it will be set to empty dict or it may be copied if it resolves as single part remote source copyprogress_listener (b2sdk.v1.AbstractProgressListener,None) – a progress listener object to use, or
None
to not report progressrecommended_upload_part_size (int,None) – the recommended part size to use for uploading local sources or
None
to determine automatically, but remote sources would be copied with maximum possible part sizecontinue_large_file_id (str,None) – large file id that should be selected to resume file creation for multipart upload/copy, if
None
in multipart case it would always start a new large fileencryption (b2sdk.v1.EncryptionSetting) – encryption settings (
None
if unknown)file_retention (b2sdk.v1.FileRetentionSetting) – file retention setting
legal_hold (bool) – legal hold setting
-
copy
(file_id, new_file_name, content_type=None, file_info=None, offset=0, length=None, progress_listener=None, destination_encryption: Optional[b2sdk.encryption.setting.EncryptionSetting] = None, source_encryption: Optional[b2sdk.encryption.setting.EncryptionSetting] = None, source_file_info: Optional[dict] = None, source_content_type: Optional[str] = None, file_retention: Optional[b2sdk.file_lock.FileRetentionSetting] = None, legal_hold: Optional[b2sdk.file_lock.LegalHold] = None)[source]¶ Creates a new file in this bucket by (server-side) copying from an existing file.
- Parameters
file_id (str) – file ID of existing file to copy from
new_file_name (str) – file name of the new file
content_type (str,None) – content_type for the new file, if
None
andb2_copy_file
will be used content_type will be copied from source file - otherwise content_type would be automatically determinedfile_info (dict,None) – file_info for the new file, if
None
will andb2_copy_file
will be used file_info will be copied from source file - otherwise it will be set to empty dictoffset (int) – offset of exisiting file that copy should start from
length (int,None) – number of bytes to copy, if
None
thenoffset
have to be0
and it will useb2_copy_file
withoutrange
parameter so it may fail if file is too large. For large files length have to be specified to useb2_copy_part
instead.progress_listener (b2sdk.v1.AbstractProgressListener,None) – a progress listener object to use for multipart copy, or
None
to not report progressdestination_encryption (b2sdk.v1.EncryptionSetting) – encryption settings for the destination (
None
if unknown)source_encryption (b2sdk.v1.EncryptionSetting) – encryption settings for the source (
None
if unknown)source_file_info (dict,None) – source file’s file_info dict, useful when copying files with SSE-C
source_content_type (str,None) – source file’s content type, useful when copying files with SSE-C
file_retention (b2sdk.v1.FileRetentionSetting) – file retention setting for the new file.
legal_hold (bool) – legal hold setting for the new file.
-