Overview
b2sdk is a client library for easy access to all of the capabilities of B2 Cloud Storage.
B2 command-line tool is an example of how it can be used to provide command-line access to the B2 service, but there are many possible applications (including FUSE filesystems, storage backend drivers for backup applications etc).
Why use b2sdk?
When building an application which uses B2 cloud, it is possible to implement an independent B2 API client, but using b2sdk allows for:
reuse of code that is already written, with hundreds of unit tests
use of Synchronizer, a high-performance, parallel rsync-like utility
developer-friendly library api version policy which guards your program against incompatible changes
B2 integration checklist is passed automatically
raw_simulator makes it easy to mock the B2 cloud for unit testing purposes
reporting progress of operations to an object of your choice
exception hierarchy makes it easy to display informative messages to users
interrupted transfers are automatically continued
b2sdk has been developed for 3 years before it version 1.0.0 was released. It’s stable and mature.
Documentation index
- Installation Guide
- Tutorial
- Quick Start Guide
- Server-Side Encryption
- Advanced usage patterns
- Glossary
- About API interfaces
- API Reference
- Interface types
- Public API
- B2 Application key
- AccountInfo
- AccountInfo implementations
- InMemoryAccountInfo
- SqliteAccountInfo
SqliteAccountInfoSqliteAccountInfo.__init__()SqliteAccountInfo.clear()SqliteAccountInfo.set_auth_data_with_schema_0_for_test()SqliteAccountInfo.get_application_key()SqliteAccountInfo.get_account_id()SqliteAccountInfo.get_application_key_id()SqliteAccountInfo.get_api_url()SqliteAccountInfo.get_account_auth_token()SqliteAccountInfo.get_download_url()SqliteAccountInfo.get_realm()SqliteAccountInfo.get_recommended_part_size()SqliteAccountInfo.get_absolute_minimum_part_size()SqliteAccountInfo.get_allowed()SqliteAccountInfo.get_s3_api_url()SqliteAccountInfo.refresh_entire_bucket_name_cache()SqliteAccountInfo.save_bucket()SqliteAccountInfo.remove_bucket_name()SqliteAccountInfo.get_bucket_id_or_none_from_bucket_name()SqliteAccountInfo.get_bucket_name_or_none_from_bucket_id()SqliteAccountInfo.list_bucket_names_ids()SqliteAccountInfo.BUCKET_UPLOAD_POOL_CLASSSqliteAccountInfo.DEFAULT_ALLOWEDSqliteAccountInfo.LARGE_FILE_UPLOAD_POOL_CLASSSqliteAccountInfo.all_capabilities()SqliteAccountInfo.allowed_is_valid()SqliteAccountInfo.clear_bucket_upload_data()SqliteAccountInfo.clear_large_file_upload_urls()SqliteAccountInfo.is_master_key()SqliteAccountInfo.is_same_account()SqliteAccountInfo.is_same_key()SqliteAccountInfo.put_bucket_upload_url()SqliteAccountInfo.put_large_file_upload_url()SqliteAccountInfo.set_auth_data()SqliteAccountInfo.take_bucket_upload_url()SqliteAccountInfo.take_large_file_upload_url()
- Implementing your own
- AccountInfo interface
AbstractAccountInfoAbstractAccountInfo.list_bucket_names_ids()AbstractAccountInfo.DEFAULT_ALLOWEDAbstractAccountInfo._abc_implAbstractAccountInfo._set_auth_data()AbstractAccountInfo.all_capabilities()AbstractAccountInfo.allowed_is_valid()AbstractAccountInfo.clear()AbstractAccountInfo.clear_bucket_upload_data()AbstractAccountInfo.clear_large_file_upload_urls()AbstractAccountInfo.get_absolute_minimum_part_size()AbstractAccountInfo.get_account_auth_token()AbstractAccountInfo.get_account_id()AbstractAccountInfo.get_allowed()AbstractAccountInfo.get_api_url()AbstractAccountInfo.get_application_key()AbstractAccountInfo.get_application_key_id()AbstractAccountInfo.get_bucket_id_or_none_from_bucket_name()AbstractAccountInfo.get_bucket_name_or_none_from_bucket_id()AbstractAccountInfo.get_download_url()AbstractAccountInfo.get_realm()AbstractAccountInfo.get_recommended_part_size()AbstractAccountInfo.get_s3_api_url()AbstractAccountInfo.is_master_key()AbstractAccountInfo.is_same_account()AbstractAccountInfo.is_same_key()AbstractAccountInfo.put_bucket_upload_url()AbstractAccountInfo.put_large_file_upload_url()AbstractAccountInfo.refresh_entire_bucket_name_cache()AbstractAccountInfo.remove_bucket_name()AbstractAccountInfo.save_bucket()AbstractAccountInfo.set_auth_data()AbstractAccountInfo.take_bucket_upload_url()AbstractAccountInfo.take_large_file_upload_url()
- AccountInfo helper classes
UrlPoolAccountInfoUrlPoolAccountInfo.BUCKET_UPLOAD_POOL_CLASSUrlPoolAccountInfo.LARGE_FILE_UPLOAD_POOL_CLASSUrlPoolAccountInfo.clear()UrlPoolAccountInfo.put_bucket_upload_url()UrlPoolAccountInfo.clear_bucket_upload_data()UrlPoolAccountInfo.take_bucket_upload_url()UrlPoolAccountInfo.put_large_file_upload_url()UrlPoolAccountInfo.take_large_file_upload_url()UrlPoolAccountInfo.clear_large_file_upload_urls()UrlPoolAccountInfo.DEFAULT_ALLOWEDUrlPoolAccountInfo.all_capabilities()UrlPoolAccountInfo.allowed_is_valid()UrlPoolAccountInfo.get_absolute_minimum_part_size()UrlPoolAccountInfo.get_account_auth_token()UrlPoolAccountInfo.get_account_id()UrlPoolAccountInfo.get_allowed()UrlPoolAccountInfo.get_api_url()UrlPoolAccountInfo.get_application_key()UrlPoolAccountInfo.get_application_key_id()UrlPoolAccountInfo.get_bucket_id_or_none_from_bucket_name()UrlPoolAccountInfo.get_bucket_name_or_none_from_bucket_id()UrlPoolAccountInfo.get_download_url()UrlPoolAccountInfo.get_realm()UrlPoolAccountInfo.get_recommended_part_size()UrlPoolAccountInfo.get_s3_api_url()UrlPoolAccountInfo.is_master_key()UrlPoolAccountInfo.is_same_account()UrlPoolAccountInfo.is_same_key()UrlPoolAccountInfo.list_bucket_names_ids()UrlPoolAccountInfo.refresh_entire_bucket_name_cache()UrlPoolAccountInfo.remove_bucket_name()UrlPoolAccountInfo.save_bucket()UrlPoolAccountInfo.set_auth_data()
UploadUrlPool
- AccountInfo interface
- AccountInfo implementations
- Cache
AbstractCacheAuthInfoCacheAuthInfoCache.__init__()AuthInfoCache.get_bucket_id_or_none_from_bucket_name()AuthInfoCache.get_bucket_name_or_none_from_bucket_id()AuthInfoCache.get_bucket_name_or_none_from_allowed()AuthInfoCache.list_bucket_names_ids()AuthInfoCache.save_bucket()AuthInfoCache.set_bucket_name_cache()AuthInfoCache.clear()
DummyCacheInMemoryCacheInMemoryCache.__init__()InMemoryCache.get_bucket_id_or_none_from_bucket_name()InMemoryCache.get_bucket_name_or_none_from_bucket_id()InMemoryCache.get_bucket_name_or_none_from_allowed()InMemoryCache.list_bucket_names_ids()InMemoryCache.save_bucket()InMemoryCache.set_bucket_name_cache()InMemoryCache.clear()
- B2 Api client
B2ApiB2Api.SESSION_CLASSB2Api.BUCKET_CLASSB2Api.BUCKET_FACTORY_CLASSB2Api.SERVICES_CLASSB2Api.FILE_VERSION_FACTORY_CLASSB2Api.__init__()B2Api.get_bucket_by_id()B2Api.DEFAULT_LIST_KEY_COUNTB2Api.DOWNLOAD_VERSION_FACTORY_CLASSB2Api.account_infoB2Api.authorize_account()B2Api.authorize_automatically()B2Api.cacheB2Api.cancel_large_file()B2Api.check_bucket_id_restrictions()B2Api.check_bucket_name_restrictions()B2Api.create_bucket()B2Api.create_key()B2Api.delete_bucket()B2Api.delete_file_version()B2Api.delete_key()B2Api.delete_key_by_id()B2Api.download_file_by_id()B2Api.get_account_id()B2Api.get_bucket_by_name()B2Api.get_download_url_for_file_name()B2Api.get_download_url_for_fileid()B2Api.get_file_info()B2Api.get_file_info_by_name()B2Api.get_key()B2Api.list_buckets()B2Api.list_keys()B2Api.list_parts()B2Api.raw_apiB2Api.update_file_legal_hold()B2Api.update_file_retention()
B2HttpApiConfig
- Exceptions
- B2 Bucket
BucketBucket.FILE_VERSION_FACTORY_CLASSBucket.get_fresh_state()Bucket.upload_bytes()Bucket.upload_local_file()Bucket.DEFAULT_CONTENT_TYPEBucket.__init__()Bucket.as_dict()Bucket.cancel_large_file()Bucket.concatenate()Bucket.concatenate_stream()Bucket.copy()Bucket.create_file()Bucket.create_file_stream()Bucket.delete_file_version()Bucket.download_file_by_id()Bucket.download_file_by_name()Bucket.get_download_authorization()Bucket.get_download_url()Bucket.get_file_info_by_id()Bucket.get_file_info_by_name()Bucket.get_id()Bucket.hide_file()Bucket.list_file_versions()Bucket.list_parts()Bucket.list_unfinished_large_files()Bucket.ls()Bucket.set_info()Bucket.set_type()Bucket.update()Bucket.upload()Bucket.upload_unbound_stream()
- File locks
- Data classes
FileVersionFileVersion.cache_controlFileVersion.as_dict()FileVersion.ADVANCED_HEADERS_LIMITFileVersion.DEFAULT_HEADERS_LIMITFileVersion.account_idFileVersion.actionFileVersion.apiFileVersion.bucket_idFileVersion.content_dispositionFileVersion.content_encodingFileVersion.content_languageFileVersion.content_md5FileVersion.content_sha1FileVersion.content_sha1_verifiedFileVersion.content_typeFileVersion.delete()FileVersion.download()FileVersion.expiresFileVersion.expires_parsed()FileVersion.file_infoFileVersion.file_nameFileVersion.file_retentionFileVersion.get_content_sha1()FileVersion.get_fresh_state()FileVersion.has_large_headerFileVersion.id_FileVersion.legal_holdFileVersion.mod_time_millisFileVersion.replication_statusFileVersion.server_side_encryptionFileVersion.sizeFileVersion.update_legal_hold()FileVersion.update_retention()FileVersion.upload_timestamp
DownloadVersionDownloadVersion.range_DownloadVersion.content_dispositionDownloadVersion.content_lengthDownloadVersion.content_languageDownloadVersion.expiresDownloadVersion.cache_controlDownloadVersion.content_encodingDownloadVersion.expires_parsed()DownloadVersion.as_dict()DownloadVersion.apiDownloadVersion.content_sha1DownloadVersion.content_sha1_verifiedDownloadVersion.content_typeDownloadVersion.delete()DownloadVersion.file_infoDownloadVersion.file_nameDownloadVersion.file_retentionDownloadVersion.get_content_sha1()DownloadVersion.id_DownloadVersion.legal_holdDownloadVersion.mod_time_millisDownloadVersion.replication_statusDownloadVersion.server_side_encryptionDownloadVersion.sizeDownloadVersion.update_legal_hold()DownloadVersion.update_retention()DownloadVersion.upload_timestamp
FileIdAndNameUnfinishedLargeFilePartRange
- Downloaded File
- Enums
- Progress reporters
- Synchronizer
- Sync Options
- Public API classes
ScanPoliciesManagerSynchronizerSyncReportSyncReport.update_compare()SyncReport.end_compare()SyncReport.update_transfer()SyncReport.UPDATE_INTERVALSyncReport.__init__()SyncReport.circular_symlink_skipped()SyncReport.close()SyncReport.end_total()SyncReport.error()SyncReport.local_access_error()SyncReport.local_permission_error()SyncReport.print_completion()SyncReport.symlink_skipped()SyncReport.update_count()SyncReport.update_total()SyncReport.stdoutSyncReport.no_progress
- Sync Encryption Settings Providers
- B2 Utility functions
- Write intent
- Outbound Transfer Source
- Encryption Settings
- Encryption Types
- Internal API
b2sdk.session– B2 SessionTokenTypeB2SessionB2Session.SQLITE_ACCOUNT_INFO_CLASSB2Session.B2HTTP_CLASSB2Session.__init__()B2Session.authorize_automatically()B2Session.authorize_account()B2Session.cancel_large_file()B2Session.create_bucket()B2Session.create_key()B2Session.delete_key()B2Session.delete_bucket()B2Session.delete_file_version()B2Session.download_file_from_url()B2Session.finish_large_file()B2Session.get_download_authorization()B2Session.get_file_info_by_id()B2Session.get_file_info_by_name()B2Session.get_upload_url()B2Session.get_upload_part_url()B2Session.hide_file()B2Session.list_buckets()B2Session.list_file_names()B2Session.list_file_versions()B2Session.list_keys()B2Session.list_parts()B2Session.list_unfinished_large_files()B2Session.start_large_file()B2Session.update_bucket()B2Session.upload_file()B2Session.upload_part()B2Session.get_download_url_by_id()B2Session.get_download_url_by_name()B2Session.copy_file()B2Session.copy_part()B2Session.update_file_retention()B2Session.update_file_legal_hold()
b2sdk.raw_api– B2 raw api wrapperMetadataDirectiveModeLifecycleRuleAbstractRawApiAbstractRawApi.authorize_account()AbstractRawApi.cancel_large_file()AbstractRawApi.copy_file()AbstractRawApi.copy_part()AbstractRawApi.create_bucket()AbstractRawApi.create_key()AbstractRawApi.download_file_from_url()AbstractRawApi.delete_key()AbstractRawApi.delete_bucket()AbstractRawApi.delete_file_version()AbstractRawApi.finish_large_file()AbstractRawApi.get_download_authorization()AbstractRawApi.get_file_info_by_id()AbstractRawApi.get_file_info_by_name()AbstractRawApi.get_upload_url()AbstractRawApi.get_upload_part_url()AbstractRawApi.hide_file()AbstractRawApi.list_buckets()AbstractRawApi.list_file_names()AbstractRawApi.list_file_versions()AbstractRawApi.list_keys()AbstractRawApi.list_parts()AbstractRawApi.list_unfinished_large_files()AbstractRawApi.start_large_file()AbstractRawApi.update_bucket()AbstractRawApi.update_file_retention()AbstractRawApi.get_upload_file_headers()AbstractRawApi.upload_file()AbstractRawApi.upload_part()AbstractRawApi.get_download_url_by_id()AbstractRawApi.get_download_url_by_name()
B2RawHTTPApiB2RawHTTPApi.__init__()B2RawHTTPApi.authorize_account()B2RawHTTPApi.cancel_large_file()B2RawHTTPApi.create_bucket()B2RawHTTPApi.create_key()B2RawHTTPApi.delete_bucket()B2RawHTTPApi.delete_file_version()B2RawHTTPApi.delete_key()B2RawHTTPApi.download_file_from_url()B2RawHTTPApi.finish_large_file()B2RawHTTPApi.get_download_authorization()B2RawHTTPApi.get_file_info_by_id()B2RawHTTPApi.get_file_info_by_name()B2RawHTTPApi.get_upload_url()B2RawHTTPApi.get_upload_part_url()B2RawHTTPApi.hide_file()B2RawHTTPApi.list_buckets()B2RawHTTPApi.list_file_names()B2RawHTTPApi.list_file_versions()B2RawHTTPApi.list_keys()B2RawHTTPApi.list_parts()B2RawHTTPApi.list_unfinished_large_files()B2RawHTTPApi.start_large_file()B2RawHTTPApi.update_bucket()B2RawHTTPApi.update_file_retention()B2RawHTTPApi.update_file_legal_hold()B2RawHTTPApi.unprintable_to_hex()B2RawHTTPApi.check_b2_filename()B2RawHTTPApi.upload_file()B2RawHTTPApi.upload_part()B2RawHTTPApi.copy_file()B2RawHTTPApi.copy_part()
b2sdk.b2http– thin http client wrapperrandom()setlocale()ResponseContextManagerHttpCallbackClockSkewHookB2HttpB2Http.CONNECTION_TIMEOUTB2Http.TIMEOUTB2Http.TIMEOUT_FOR_COPYB2Http.TIMEOUT_FOR_UPLOADB2Http.TRY_COUNT_DATAB2Http.TRY_COUNT_DOWNLOADB2Http.TRY_COUNT_HEADB2Http.TRY_COUNT_OTHERB2Http.add_callback()B2Http.post_content_return_json()B2Http.post_json_return_json()B2Http.get_content()B2Http.head_content()
NotDecompressingHTTPAdaptertest_http()
b2sdk.requests– modified requests.models.Response classb2sdk.utilsb2_url_encode()b2_url_decode()choose_part_ranges()update_digest_from_stream()hex_sha1_of_stream()IncrementalHexDigesterhex_sha1_of_unlimited_stream()hex_sha1_of_file()hex_sha1_of_bytes()hex_md5_of_bytes()md5_of_bytes()b64_of_bytes()validate_b2_file_name()is_file_readable()get_file_mtime()is_special_file()set_file_mtime()fix_windows_path_limit()format_and_scale_number()format_and_scale_fraction()camelcase_to_underscore()B2TraceMetaB2TraceMetaAbstractConcurrentUsedAuthTokenGuardcurrent_time_millis()iterator_peek()
b2sdk.cacheb2sdk.stream.chainedChainedStreamb2sdk.stream.hashingStreamWithHashb2sdk.stream.progressStreams with progress reportingb2sdk.stream.rangeRangeOfInputStreamb2sdk.stream.wrapperStreamWrapperb2sdk.scan.folder_parserb2sdk.scan.folderb2sdk.scan.pathb2sdk.scan.policiesb2sdk.scan.scanb2sdk.sync.actionb2sdk.sync.exceptionb2sdk.sync.policyb2sdk.sync.policy_managerb2sdk.sync.syncb2sdk.transfer.inbound.downloader.abstract– Downloader base classb2sdk.transfer.inbound.downloader.parallel– ParallelTransfererb2sdk.transfer.inbound.downloader.simple– SimpleDownloaderb2sdk.transfer.inbound.download_manager– Manager of downloadersb2sdk.transfer.outbound.upload_sourceb2sdk.raw_simulator– B2 raw api simulatorget_bytes_range()KeySimulatorPartSimulatorFileSimulatorFileSimulator.CHECK_ENCRYPTIONFileSimulator.SPECIAL_FILE_INFOSFileSimulator.__init__()FileSimulator.dont_check_encryption()FileSimulator.sort_key()FileSimulator.as_download_headers()FileSimulator.as_upload_result()FileSimulator.as_list_files_dict()FileSimulator.is_allowed_to_read_file_retention()FileSimulator.is_allowed_to_read_file_legal_hold()FileSimulator.as_start_large_file_result()FileSimulator.add_part()FileSimulator.finish()FileSimulator.is_visible()FileSimulator.list_parts()FileSimulator.check_encryption()
FakeRequestFakeResponseBucketSimulatorBucketSimulator.FIRST_FILE_NUMBERBucketSimulator.FIRST_FILE_IDBucketSimulator.FILE_SIMULATOR_CLASSBucketSimulator.RESPONSE_CLASSBucketSimulator.MAX_SIMPLE_COPY_SIZEBucketSimulator.__init__()BucketSimulator.get_file()BucketSimulator.is_allowed_to_read_bucket_encryption_setting()BucketSimulator.is_allowed_to_read_bucket_retention()BucketSimulator.bucket_dict()BucketSimulator.cancel_large_file()BucketSimulator.delete_file_version()BucketSimulator.download_file_by_id()BucketSimulator.download_file_by_name()BucketSimulator.finish_large_file()BucketSimulator.get_file_info_by_id()BucketSimulator.get_file_info_by_name()BucketSimulator.get_upload_url()BucketSimulator.get_upload_part_url()BucketSimulator.hide_file()BucketSimulator.update_file_retention()BucketSimulator.update_file_legal_hold()BucketSimulator.copy_file()BucketSimulator.list_file_names()BucketSimulator.list_file_versions()BucketSimulator.list_parts()BucketSimulator.list_unfinished_large_files()BucketSimulator.start_large_file()BucketSimulator.upload_file()BucketSimulator.upload_part()
RawSimulatorRawSimulator.BUCKET_SIMULATOR_CLASSRawSimulator.API_URLRawSimulator.S3_API_URLRawSimulator.DOWNLOAD_URLRawSimulator.MIN_PART_SIZERawSimulator.MAX_PART_IDRawSimulator.MAX_DURATION_IN_SECONDSRawSimulator.UPLOAD_PART_MATCHERRawSimulator.UPLOAD_URL_MATCHERRawSimulator.DOWNLOAD_URL_MATCHERRawSimulator.__init__()RawSimulator.expire_auth_token()RawSimulator.create_account()RawSimulator.set_upload_errors()RawSimulator.authorize_account()RawSimulator.cancel_large_file()RawSimulator.create_bucket()RawSimulator.create_key()RawSimulator.delete_file_version()RawSimulator.update_file_retention()RawSimulator.update_file_legal_hold()RawSimulator.delete_bucket()RawSimulator.download_file_from_url()RawSimulator.delete_key()RawSimulator.finish_large_file()RawSimulator.get_download_authorization()RawSimulator.get_file_info_by_id()RawSimulator.get_file_info_by_name()RawSimulator.get_upload_url()RawSimulator.get_upload_part_url()RawSimulator.hide_file()RawSimulator.copy_file()RawSimulator.copy_part()RawSimulator.list_buckets()RawSimulator.list_file_names()RawSimulator.list_file_versions()RawSimulator.list_keys()RawSimulator.list_parts()RawSimulator.list_unfinished_large_files()RawSimulator.start_large_file()RawSimulator.update_bucket()RawSimulator.get_upload_file_headers()RawSimulator.upload_file()RawSimulator.upload_part()
- Contributors Guide