aiob2 is a asyncio-based Backblaze B2 client for Python.
This library will allow you to easily interact with B2 buckets and files as first class objects in Python 3.5+.
This is a hard-fork of sibblegp/b2blaze. changed to use aiohttp instead of requests.
aiob2 requires Python 3.5.2+, and will not work on any olderversion of Python. To install aiob2, run the following command in the proper environment:
pip install aiob2
# Construct the B2 Client
from aiob2 import B2
# The client requires a aiohttp.ClientSession to operate under.
async with aiohttp.ClientSession() as session:
b2_client = B2()
# Authorize the client via enviorment vairables
await b2_client.authorize()
# Or explicitly authorize with keys.
await b2_client.authorize(key_id, application_key)
The B2 object is how you access aiob2's functionality. You can optionally pass in "key_id" and "application_key" as named arguments but you should probably set them as environment variable as described above.
Buckets are essentially the highest level folders in B2, similar to how buckets are used in AWS S3.
bucket_id
bucket_name
bucket_type
bucket_info
lifecycle_rules
revision
cors_rules
deleted
async for bucket in b2.buckets.all():
# iterate throug buckets
bucket = await b2.buckets.create('test_bucket', security=b2.buckets.public)
Buckets can either be public or private. This does not change the functionality of the library other than that you will need to manually authorize when using file URLs (see below).
bucket_by_name = await b2.buckets.get('test_bucket')
bucket_by_id = await b2.buckets.get(bucket_id='abcd')