Skip to content
forked from sibblegp/b2blaze

An asyncio-based Backblaze B2 client for Python.

License

Notifications You must be signed in to change notification settings

james7132/aiob2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aiob2

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.

Installation

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

Usage

The B2 Object

# 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

Buckets are essentially the highest level folders in B2, similar to how buckets are used in AWS S3.

Bucket Properties

bucket_id
bucket_name
bucket_type
bucket_info
lifecycle_rules
revision
cors_rules
deleted

List All Buckets

async for bucket in b2.buckets.all():
    # iterate throug buckets

Create a Bucket

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).

Retrieve a bucket

bucket_by_name = await b2.buckets.get('test_bucket')
bucket_by_id = await b2.buckets.get(bucket_id='abcd')

Delete a bucket