b2sdk.raw_api
– B2 raw api wrapper¶
-
class
b2sdk.raw_api.
MetadataDirectiveMode
(value)[source]¶ Bases:
enum.Enum
Mode of handling metadata when copying a file
-
COPY
= 401¶ copy metadata from the source file
-
REPLACE
= 402¶ ignore the source file metadata and set it to provided values
-
-
class
b2sdk.raw_api.
AbstractRawApi
[source]¶ Bases:
object
Direct access to the B2 web apis.
-
abstract
copy_file
(api_url, account_auth_token, source_file_id, new_file_name, bytes_range=None, metadata_directive=None, content_type=None, file_info=None, destination_bucket_id=None)[source]¶
-
abstract
copy_part
(api_url, account_auth_token, source_file_id, large_file_id, part_number, bytes_range=None)[source]¶
-
abstract
create_bucket
(api_url, account_auth_token, account_id, bucket_name, bucket_type, bucket_info=None, cors_rules=None, lifecycle_rules=None)[source]¶
-
abstract
create_key
(api_url, account_auth_token, account_id, capabilities, key_name, valid_duration_seconds, bucket_id, name_prefix)[source]¶
-
abstract
get_file_info_by_id
(api_url: str, account_auth_token: str, file_id: str) → Dict[str, Any][source]¶
-
abstract
get_file_info_by_name
(download_url: str, account_auth_token: str, bucket_name: str, file_name: str) → Dict[str, Any][source]¶
-
abstract
list_buckets
(api_url, account_auth_token, account_id, bucket_id=None, bucket_name=None)[source]¶
-
abstract
list_file_names
(api_url, account_auth_token, bucket_id, start_file_name=None, max_file_count=None, prefix=None)[source]¶
-
abstract
list_file_versions
(api_url, account_auth_token, bucket_id, start_file_name=None, start_file_id=None, max_file_count=None, prefix=None)[source]¶
-
abstract
list_keys
(api_url, account_auth_token, account_id, max_key_count=None, start_application_key_id=None)[source]¶
-
abstract
list_parts
(api_url, account_auth_token, file_id, start_part_number, max_part_count)[source]¶
-
abstract
list_unfinished_large_files
(api_url, account_auth_token, bucket_id, start_file_id=None, max_file_count=None, prefix=None)[source]¶
-
abstract
start_large_file
(api_url, account_auth_token, bucket_id, file_name, content_type, file_info)[source]¶
-
abstract
update_bucket
(api_url, account_auth_token, account_id, bucket_id, bucket_type=None, bucket_info=None, cors_rules=None, lifecycle_rules=None, if_revision_is=None)[source]¶
-
abstract
upload_file
(upload_url, upload_auth_token, file_name, content_length, content_type, content_sha1, file_infos, data_stream)[source]¶
-
abstract
-
class
b2sdk.raw_api.
B2RawApi
(b2_http)[source]¶ Bases:
b2sdk.raw_api.AbstractRawApi
Provide access to the B2 web APIs, exactly as they are provided by b2.
Requires that you provide all necessary URLs and auth tokens for each call.
Each API call decodes the returned JSON and returns a dict.
- For details on what each method does, see the B2 docs:
This class is intended to be a super-simple, very thin layer on top of the HTTP calls. It can be mocked-out for testing higher layers. And this class can be tested by exercising each call just once, which is relatively quick.
-
create_bucket
(api_url, account_auth_token, account_id, bucket_name, bucket_type, bucket_info=None, cors_rules=None, lifecycle_rules=None)[source]¶
-
create_key
(api_url, account_auth_token, account_id, capabilities, key_name, valid_duration_seconds, bucket_id, name_prefix)[source]¶
-
download_file_from_url
(account_auth_token_or_none, url, range_=None)[source]¶ Issue a streaming request for download of a file, potentially authorized.
- Parameters
account_auth_token_or_none – an optional account auth token to pass in
url – the full URL to download from
range – two-element tuple for http Range header
- Returns
b2_http response
-
get_file_info_by_name
(download_url: str, account_auth_token: str, bucket_name: str, file_name: str) → Dict[str, Any][source]¶
-
list_file_names
(api_url, account_auth_token, bucket_id, start_file_name=None, max_file_count=None, prefix=None)[source]¶
-
list_file_versions
(api_url, account_auth_token, bucket_id, start_file_name=None, start_file_id=None, max_file_count=None, prefix=None)[source]¶
-
list_keys
(api_url, account_auth_token, account_id, max_key_count=None, start_application_key_id=None)[source]¶
-
list_unfinished_large_files
(api_url, account_auth_token, bucket_id, start_file_id=None, max_file_count=None, prefix=None)[source]¶
-
start_large_file
(api_url, account_auth_token, bucket_id, file_name, content_type, file_info)[source]¶
-
update_bucket
(api_url, account_auth_token, account_id, bucket_id, bucket_type=None, bucket_info=None, cors_rules=None, lifecycle_rules=None, if_revision_is=None)[source]¶
-
unprintable_to_hex
(string)[source]¶ Replace unprintable chars in string with a hex representation.
- Parameters
string – an arbitrary string, possibly with unprintable characters.
- Returns
the string, with unprintable characters changed to hex (e.g., “”)
-
check_b2_filename
(filename)[source]¶ Raise an appropriate exception with details if the filename is unusable.
See https://www.backblaze.com/b2/docs/files.html for the rules.
- Parameters
filename – a proposed filename in unicode
- Returns
None if the filename is usable
-
upload_file
(upload_url, upload_auth_token, file_name, content_length, content_type, content_sha1, file_infos, data_stream)[source]¶ Upload one, small file to b2.
- Parameters
upload_url – the upload_url from b2_authorize_account
upload_auth_token – the auth token from b2_authorize_account
file_name – the name of the B2 file
content_length – number of bytes in the file
content_type – MIME type
content_sha1 – hex SHA1 of the contents of the file
file_infos – extra file info to upload
data_stream – a file like object from which the contents of the file can be read
- Returns
-
upload_part
(upload_url, upload_auth_token, part_number, content_length, content_sha1, data_stream)[source]¶
-
b2sdk.raw_api.
test_raw_api
()[source]¶ Exercise the code in B2RawApi by making each call once, just to make sure the parameters are passed in, and the result is passed back.
The goal is to be a complete test of B2RawApi, so the tests for the rest of the code can use the simulator.
Prints to stdout if things go wrong.
- Returns
0 on success, non-zero on failure
-
b2sdk.raw_api.
test_raw_api_helper
(raw_api)[source]¶ Try each of the calls to the raw api. Raise an exception if anything goes wrong.
This uses a Backblaze account that is just for this test. The account uses the free level of service, which should be enough to run this test a reasonable number of times each day. If somebody abuses the account for other things, this test will break and we’ll have to do something about it.