API

Base

class backblaze.base.Base(key_id: str, key: str, timeout: int = 30, chunk_size: int = 5000024)

Awaiting

class backblaze.Awaiting(*args, **kwargs)
await authorize() backblaze.models.auth.AuthModel

Used to authorize B2 account.

Returns

Holds data on account auth.

Return type

AuthModel

bucket(bucket_id: str) backblaze.bucket.awaiting.AwaitingBucket

Used to interact with a bucket.

Parameters

bucket_id (str) – ID of Bucket.

Returns

Return type

AwaitingBucket

async for ... in buckets(types: list = ['all']) AsyncGenerator[Tuple[backblaze.models.bucket.BucketModel, backblaze.bucket.awaiting.AwaitingBucket], None]

Lists buckets.

Parameters

types (list, optional) – Used to filter bucket types, by default [“all”]

Yields
  • BucketModel – Holds details on bucket.

  • AwaitingBucket – Used for interacting with bucket.

await close() None

Closes any underlying TCP sessions.

await create_bucket(settings: backblaze.settings.BucketSettings) Tuple[backblaze.models.bucket.BucketModel, backblaze.bucket.awaiting.AwaitingBucket]

Used to create a bucket.

Parameters

settings (BucketSettings) – Holds bucket settings.

Returns

  • BucketModel – Holds details on a bucket.

  • AwaitingBucket – Used to interact with a bucket.

await create_key(settings: backblaze.settings.KeySettings) Tuple[backblaze.models.key.KeyModel, backblaze.key.awaiting.AwaitingKey]

Used to create a key.

Parameters

settings (KeySettings) – Used to hold details on a key.

Returns

  • KeyModel – Holds details on key.

  • AwaitingKey

await download_by_name(bucket_name: str, file_name: str, settings: backblaze.settings.DownloadSettings = None) bytes

Used to download a file by its name.

Parameters
  • bucket_name (str) – Name of bucket.

  • file_name (str) – Name of file to download.

  • settings (DownloadSettings, optional) – by default None

Returns

Return type

bytes

Notes

Use bucket.file.download instead whenever you can.

key(key_id: str) backblaze.key.awaiting.AwaitingKey

Used to interact with key.

Parameters

key_id (str) – ID of key.

Returns

Return type

AwaitingKey

async for ... in keys(limit: int = 100, start_key_id: str = None) AsyncGenerator[Tuple[backblaze.models.key.KeyModel, backblaze.key.awaiting.AwaitingKey, str], None]

Used to list keys.

Parameters
  • limit (int, optional) – Used to limit the listing, by default 100

  • start_key_id (str, optional) – Key to start listing from, by default None

Yields
  • KeyModel – Holds details on key.

  • AwaitingKey

  • str – Next application key ID.

Key

class backblaze.key.awaiting.AwaitingKey
await delete() backblaze.models.key.KeyModel

Used delete key.

Returns

Details on delete key.

Return type

KeyModel

Bucket

class backblaze.bucket.awaiting.AwaitingBucket
await create_part(settings: backblaze.settings.PartSettings) Tuple[backblaze.models.file.FileModel, backblaze.bucket.awaiting.file.AwaitingFile]

Used to create a part.

Parameters

settings (PartSettings) –

Returns

  • FileModel

  • AwaitingFile

await delete() backblaze.models.bucket.BucketModel

Used to delete a bucket.

Returns

Holds details on delete bucked.

Return type

BucketModel

file(file_id: str) backblaze.bucket.awaiting.file.AwaitingFile

Used to interact with a file.

Parameters

file_id (str) – ID of a file.

Returns

Return type

AwaitingFile

async for ... in file_names(settings: backblaze.settings.FileSettings = None) AsyncGenerator[Tuple[backblaze.models.file.FileModel, backblaze.bucket.awaiting.file.AwaitingFile, str], None]

Used to list file by name.

Parameters

settings (FileSettings, optional) – by default None

Yields
  • FileModel – Holds details on file.

  • AwaitingFile

  • str – Next file name.

async for ... in file_versions(settings: backblaze.settings.FileSettings = None) AsyncGenerator[Tuple[backblaze.models.file.FileModel, backblaze.bucket.awaiting.file.AwaitingFile, str, str], None]

Used to list file by version.

Parameters

settings (FileSettings, optional) – by default None

Yields
  • FileModel – Holds details on file.

  • AwaitingFile

  • str – Next file name.

  • str – Next file ID.

await update(settings: backblaze.settings.BucketUpdateSettings) backblaze.models.bucket.BucketModel

Updates bucket details.

Parameters

settings (BucketUpdateSettings) –

Returns

Return type

BucketModel

await upload(settings: backblaze.settings.UploadSettings, data: bytes) Tuple[backblaze.models.file.FileModel, backblaze.bucket.awaiting.file.AwaitingFile]

Used to upload a file to b2.

Parameters
Returns

  • FileModel – Holds details on the uploaded file.

  • AwaitingFile – Used to interact with the file.

await upload_file(settings: backblaze.settings.UploadSettings, pathway: str, allow_parts: bool = True) Tuple[backblaze.models.file.FileModel, backblaze.bucket.awaiting.file.AwaitingFile]

Used to upload a file to the bucket.

Parameters
  • settings (UploadSettings) –

  • pathway (str) –

  • allow_parts (bool, optional) – by default True

Returns

  • FileModel – Holds details on the uploaded file.

  • AwaitingFile – Used to interact with the file.

Notes

If file size above 5mb file will be uploaded in parts.

await upload_url() backblaze.models.file.UploadUrlModel

Used to get a upload URL.

Returns

Holds details on the upload URL.

Return type

UploadUrlModel

Notes

Caching is used.

File

class backblaze.bucket.awaiting.file.AwaitingFile
await cancel() backblaze.models.file.PartCancelModel

Used for cancelling a uncompleted file.

Returns

Holds details on canceled file.

Return type

PartCancelModel

await copy(settings: backblaze.settings.CopyFileSettings) Tuple[backblaze.models.file.FileModel, backblaze.bucket.awaiting.file.AwaitingFile]

Used copy a file.

Parameters

settings (CopyFileSettings) –

Returns

  • FileModel

  • AwaitingFile

await delete(name: str = None) backblaze.models.file.FileDeleteModel

Deletes give file.

Parameters

name (str, optional) – Name of file, if not given calls self.get, by default None.

Returns

Holds details on delete file.

Return type

FileDeleteModel

await download(settings: backblaze.settings.DownloadSettings = None) bytes

Used to download file into memory.

Parameters

settings (DownloadSettings) –

Returns

Return type

bytes

async for ... in download_iterate(settings: backblaze.settings.DownloadSettings = None) AsyncGenerator[bytes, None]

Used to iterate over the download.

Parameters

settings (DownloadSettings) –

Yields

bytes

Notes

This is recommended for downloading files because its more memory efficient.

await get() backblaze.models.file.FileModel

Used to get details on a file.

Returns

Holds details on a file

Return type

FileModel

parts(part_number: int = 0) backblaze.bucket.awaiting.part.AwaitingParts

Used to upload a parts.

Parameters

part_number (int, optional) – by default 0

Returns

Return type

AwaitingParts

await save(settings: backblaze.settings.DownloadSettings, pathway: str) None

Used to save a file to a local pathway.

Parameters

Notes

Saves file in chunks to be more memory efficient.

await upload_url() backblaze.models.file.UploadUrlModel

Used to get a part upload URL.

Returns

Holds details on the upload URL.

Return type

UploadUrlModel

Notes

Caching is used.

Part

class backblaze.bucket.awaiting.part.AwaitingParts
await copy(settings: backblaze.settings.CopyPartSettings) backblaze.models.file.PartModel

Used to copy a part.

Parameters

settings (CopyPartSettings) –

Returns

Return type

PartModel

await data(data: bytes) backblaze.models.file.PartModel

Uploads a part.

Parameters

data (bytes) –

Returns

Holds details on upload part.

Return type

PartModel

await file(pathway: str) None

Used to upload a file in parts.

Parameters

pathway (str) – Local file pathway.

await finish() backblaze.models.file.FileModel

Used to complete a part upload.

Returns

Holds details on uploaded file.

Return type

FileModel

async for ... in list(limit: int = 100) AsyncGenerator[Tuple[backblaze.models.file.PartModel, int], None]

Used to list parts.

Yields
  • PartModel

  • int – Next part number.

  • limit (int) – Part limit.

Blocking

class backblaze.Blocking(*args, **kwargs)
authorize() backblaze.models.auth.AuthModel

Used to authorize B2 account.

Returns

Holds data on account auth.

Return type

AuthModel

bucket(bucket_id: str) backblaze.bucket.blocking.BlockingBucket

Used to interact with a bucket.

Parameters

bucket_id (str) – ID of Bucket.

Returns

Return type

BlockingBucket

for ... in buckets(types: list = ['all']) Generator[Tuple[backblaze.models.bucket.BucketModel, backblaze.bucket.blocking.BlockingBucket], None, None]

Lists buckets.

Parameters

types (list, optional) – Used to filter bucket types, by default [“all”]

Yields
  • BucketModel – Holds details on bucket.

  • BlockingBucket – Used for interacting with bucket.

close() None

Closes any underlying TCP sessions.

create_bucket(settings: backblaze.settings.BucketSettings) Tuple[backblaze.models.bucket.BucketModel, backblaze.bucket.blocking.BlockingBucket]

Used to create a bucket.

Parameters

settings (BucketSettings) – Holds bucket settings.

Returns

  • BucketModel – Holds details on a bucket.

  • BlockingBucket – Used to interact with a bucket.

create_key(settings: backblaze.settings.KeySettings) Tuple[backblaze.models.key.KeyModel, backblaze.key.blocking.BlockingKey]

Used to create a key.

Parameters

settings (KeySettings) – Used to hold details on a key.

Returns

  • KeyModel – Holds details on key.

  • BlockingKey

download_by_name(bucket_name: str, file_name: str, settings: backblaze.settings.DownloadSettings = None) bytes

Used to download a file by its name.

Parameters
  • bucket_name (str) – Name of bucket.

  • file_name (str) – Name of file to download.

  • settings (DownloadSettings, optional) – by default None

Returns

Return type

bytes

Notes

Use bucket.file.download instead whenever you can.

key(key_id: str) backblaze.key.blocking.BlockingKey

Used to interact with key.

Parameters

key_id (str) – ID of key.

Returns

Return type

BlockingKey

for ... in keys(limit: int = 100, start_key_id: str = None) Generator[Tuple[backblaze.models.key.KeyModel, backblaze.key.blocking.BlockingKey], None, None]

Used to list keys.

Parameters
  • limit (int, optional) – Used to limit the listing, by default 100

  • start_key_id (str, optional) – Key to start listing from, by default None

Yields
  • KeyModel – Holds details on key.

  • BlockingKey

Key

class backblaze.key.blocking.BlockingKey
delete() backblaze.models.key.KeyModel

Used delete key.

Returns

Details on delete key.

Return type

KeyModel

Bucket

class backblaze.bucket.blocking.BlockingBucket
create_part(settings: backblaze.settings.PartSettings) Tuple[backblaze.models.file.FileModel, backblaze.bucket.blocking.file.BlockingFile]

Used to create a part.

Parameters

settings (PartSettings) –

Returns

  • FileModel

  • BlockingFile

delete() backblaze.models.bucket.BucketModel

Used to delete a bucket.

Returns

Holds details on delete bucked.

Return type

BucketModel

file(file_id: str) backblaze.bucket.blocking.file.BlockingFile

Used to interact with a file.

Parameters

file_id (str) – ID of a file.

Returns

Return type

BlockingFile

for ... in file_names(settings: backblaze.settings.FileSettings = None) Generator[Tuple[backblaze.models.file.FileModel, backblaze.bucket.blocking.file.BlockingFile, str], None, None]

Used to list file by name.

Parameters

settings (FileSettings, optional) – by default None

Yields
  • FileModel – Holds details on file.

  • BlockingFile

  • str – Next file name.

for ... in file_versions(settings: backblaze.settings.FileSettings = None) Generator[Tuple[backblaze.models.file.FileModel, backblaze.bucket.blocking.file.BlockingFile, str, str], None, None]

Used to list file by version.

Parameters

settings (FileSettings, optional) – by default None

Yields
  • FileModel – Holds details on file.

  • BlockingFile

  • str – Next file name.

  • str – Next file ID

update(settings: backblaze.settings.BucketUpdateSettings) backblaze.models.bucket.BucketModel

Updates bucket details.

Parameters

settings (BucketUpdateSettings) –

Returns

Return type

BucketModel

upload(settings: backblaze.settings.UploadSettings, data: bytes) Tuple[backblaze.models.file.FileModel, backblaze.bucket.blocking.file.BlockingFile]

Used to upload a file to b2.

Parameters
Returns

  • FileModel – Holds details on the uploaded file.

  • BlockingFile – Used to interact with the file.

upload_file(settings: backblaze.settings.UploadSettings, pathway: str, allow_parts: bool = True) Tuple[backblaze.models.file.FileModel, backblaze.bucket.blocking.file.BlockingFile]

Used to upload a file to the bucket.

Parameters
  • settings (UploadSettings) –

  • pathway (str) –

  • allow_parts (bool, optional) – by default True

Returns

  • FileModel – Holds details on the uploaded file.

  • BlockingFile – Used to interact with the file.

Notes

If file size above 5mb file will be uploaded in parts.

upload_url() backblaze.models.file.UploadUrlModel

Used to get a upload URL.

Returns

Holds details on the upload URL.

Return type

UploadUrlModel

Notes

Caching is used.

File

class backblaze.bucket.blocking.file.BlockingFile
cancel() backblaze.models.file.PartCancelModel

Used for cancelling a uncompleted file.

Returns

Holds details on canceled file.

Return type

PartCancelModel

copy(settings: backblaze.settings.CopyFileSettings) Tuple[backblaze.models.file.FileModel, backblaze.bucket.blocking.file.BlockingFile]

Used copy a file.

Parameters

settings (CopyFileSettings) –

Returns

  • FileModel

  • BlockingFile

delete(name: str = None) backblaze.models.file.FileDeleteModel

Deletes give file.

Parameters

name (str, optional) – Name of file, if not given calls self.get, by default None.

Returns

Holds details on delete file.

Return type

FileDeleteModel

download(settings: backblaze.settings.DownloadSettings = None) bytes

Used to download file into memory.

Parameters

settings (DownloadSettings) –

Returns

Return type

bytes

download_iterate() None

This doesn’t work, only here for a identical API.

Raises

AwaitingOnly – Raised when a coroutine called is awaiting supported only.

get() backblaze.models.file.FileModel

Used to get details on a file.

Returns

Holds details on a file

Return type

FileModel

parts(part_number: int = 0) backblaze.bucket.blocking.part.BlockingParts

Used to upload a parts.

Parameters

part_number (int, optional) – by default 0

Returns

Return type

BlockingParts

save(settings: backblaze.settings.DownloadSettings, pathway: str) None

Used to save a file to a local pathway.

Parameters
upload_url() backblaze.models.file.UploadUrlModel

Used to get a part upload URL.

Returns

Holds details on the upload URL.

Return type

UploadUrlModel

Notes

Caching is used.

Part

class backblaze.bucket.blocking.part.BlockingParts
copy(settings: backblaze.settings.CopyPartSettings) backblaze.models.file.PartModel

Used to copy a part.

Parameters

settings (CopyPartSettings) –

Returns

Return type

PartModel

data(data: bytes) backblaze.models.file.PartModel

Uploads a part.

Parameters

data (bytes) –

Returns

Holds details on upload part.

Return type

PartModel

file(pathway: str) None

Used to upload a file in parts.

Parameters

pathway (str) – Local file pathway.

finish() backblaze.models.file.FileModel

Used to complete a part upload.

Returns

Holds details on uploaded file.

Return type

FileModel

for ... in list(limit: int = 100) Generator[Tuple[backblaze.models.file.PartModel, int], int, None]

Used to list parts.

Yields
  • PartModel

  • int – Next part number.

  • limit (int) – Part limit.