libcloud.storage.drivers.backblaze_b2 module
Driver for Backblaze B2 service.
- class libcloud.storage.drivers.backblaze_b2.BackblazeB2AuthConnection(*args, **kwargs)[source]
Bases:
ConnectionUserAndKeyInitialize user_id and key; set secure to an
intbased on passed value.- authenticate(force=False)[source]
- Parameters:
force (
bool) – Force authentication if if we have already obtained the token.
- responseCls
alias of
BackblazeB2Response
- secure = True
- class libcloud.storage.drivers.backblaze_b2.BackblazeB2Connection(*args, **kwargs)[source]
Bases:
ConnectionUserAndKeyInitialize user_id and key; set secure to an
intbased on passed value.- authCls
alias of
BackblazeB2AuthConnection
- request(action, params=None, data=None, headers=None, method='GET', raw=False, include_account_id=False)[source]
Request a given action.
Basically a wrapper around the connection object’s request that does some helpful pre-processing.
- Parameters:
action (
str) – A path. This can include arguments. If included, any extra parameters are appended to the existing ones.params (
dict) – Optional mapping of additional parameters to send. If None, leave as an emptydict.data (
unicode) – A body of data to send with the request.headers (
dict) – Extra headers to add to the request None, leave as an emptydict.method (
str) – An HTTP method such as “GET” or “POST”.raw (
bool) – True to perform a “raw” request aka only send the headers and use the rawResponseCls class. This is used with storage API when uploading a file.stream (
bool) – True to return an iterator in Response.iter_content and allow streaming of the response data (for downloading large files)retry_failed – True if failed requests should be retried. This argument can override module level constant and environment variable value on per-request basis.
- Returns:
An
Responseinstance.- Return type:
Responseinstance
- responseCls
alias of
BackblazeB2Response
- secure = True
- class libcloud.storage.drivers.backblaze_b2.BackblazeB2StorageDriver(key, secret=None, secure=True, host=None, port=None, api_version=None, region=None, **kwargs)[source]
Bases:
StorageDriver- Parameters:
key (
str) – API key or username to be used (required)secret (
str) – Secret password to be used (required)secure (
bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.host (
str) – Override hostname used for connections.port (
int) – Override port used for connections.api_version (
str) – Optional API version. Only used by drivers which support multiple API versions.region (
str) – Optional driver region. Only used by drivers which support multiple regions.
- Return type:
None
- connectionCls
alias of
BackblazeB2Connection
- create_container(container_name, ex_type='allPrivate')[source]
Create a new container.
- Parameters:
container_name (
str) – Container name.- Returns:
Container instance on success.
- Return type:
- delete_container(container)[source]
Delete a container.
- Parameters:
container (
libcloud.storage.base.Container) – Container instance- Returns:
Trueon success,Falseotherwise.- Return type:
bool
- delete_object(obj)[source]
Delete an object.
- Parameters:
obj (
libcloud.storage.base.Object) – Object instance.- Returns:
boolTrue on success.- Return type:
bool
- download_object(obj, destination_path, overwrite_existing=False, delete_on_failure=True)[source]
Download an object to the specified destination path.
- Parameters:
obj (
libcloud.storage.base.Object) – Object instance.destination_path (
str) – Full path to a file or a directory where the incoming file will be saved.overwrite_existing (
bool) – True to overwrite an existing file, defaults to False.delete_on_failure (
bool) – True to delete a partially downloaded file if the download was not successful (hash mismatch / file size).
- Returns:
True if an object has been successfully downloaded, False otherwise.
- Return type:
bool
- download_object_as_stream(obj, chunk_size=None)[source]
Return a iterator which yields object data.
- Parameters:
obj (
libcloud.storage.base.Object) – Object instancechunk_size (
int) – Optional chunk size (in bytes).
- Return type:
iteratorofbytes
- ex_get_upload_data(container_id)[source]
Retrieve information used for uploading files (upload url, auth token, etc).
- Rype:
dict
- ex_list_object_versions(container_id, ex_start_file_name=None, ex_start_file_id=None, ex_max_file_count=None)[source]
- get_container(container_name)[source]
Return a container instance.
- Parameters:
container_name (
str) – Container name.- Returns:
Containerinstance.- Return type:
- get_object(container_name, object_name)[source]
Return an object instance.
- Parameters:
container_name (
str) – Container name.object_name (
str) – Object name.
- Returns:
Objectinstance.- Return type:
- iterate_container_objects(container, prefix=None, ex_prefix=None)[source]
Return a generator of objects for the given container.
- Parameters:
container (
Container) – Container instanceprefix (
str) – Filter objects starting with a prefix. Filtering is performed client-side.ex_prefix (
str) – (Deprecated.) Filter objects starting with a prefix. Filtering is performed client-side.
- Returns:
A generator of Object instances.
- Return type:
generatorofObject
- iterate_containers()[source]
Return a iterator of containers for the given account
- Returns:
A iterator of Container instances.
- Return type:
iteratoroflibcloud.storage.base.Container
- type = 'backblaze_b2'
- upload_object(file_path, container, object_name, extra=None, verify_hash=True, headers=None)[source]
Upload an object.
Note: This will override file with a same name if it already exists.
- upload_object_via_stream(iterator, container, object_name, extra=None, headers=None)[source]
Upload an object.
Note: Backblaze does not yet support uploading via stream, so this calls upload_object internally requiring the object data to be loaded into memory at once
- website = 'https://www.backblaze.com/b2/'