Skip to main content

A simple and easy to use async wrapper for Backblaze's B2 bucket API.

Project description

aiob2


Python Version PyPi License

aiob2 is an asynchronous API wrapper for the Backblaze B2 Bucket API.

It will allow you to interact with your B2 bucket, it's files and anything else that the B2 API allows in a modern, object-oriented fashion.

NOTE: This API wrapper is by no means complete and has many endpoints to cover, though the main ones have been covered (they will be listed below)

Installation


aiob2 is compatible with Python 3.8.10+ (this is an estimate). To install aiob2, run the following command in your (virtual) environment.

pip install aiob2

Alternatively, for the latest though least stable version, you can download it from the GitHub repo:

pip install git+https://github.com/Void-ux/aiob2.git

Usage

Uploading

import aiohttp
import asyncio

from aiob2 import B2ConnectionInfo, bucket

# Construct our connection info
conn_info = B2ConnectionInfo('key_id', 'app_id')

# Our image to upload to our bucket
with open(r'C:\Users\MS1\Pictures\Camera Roll\IMG_5316.jpeg', 'rb') as file:
    data = file.read()

async def main():
    async with aiohttp.ClientSession() as s:
        await bucket.upload_file(
            content_bytes=data,
            content_type='image/jpeg',
            file_name='home.jpeg',
            session=s,
            bucket_id='bucket_id',
            conn_info=conn_info
        )


if __name__ == '__main__':
    asyncio.run(main())

And that's it! upload_file() returns a File object that neatly wraps everything Backblaze's API has provided us with. The File object has the following attributes:

account_id
action
bucket_id
content_length
content_sha1
content_md5
content_type
file_id
file_info
file_name
file_retention
legal_hold
server_side_encryption
upload_timestamp

You can visit the bucket.py file to view the source code of this class.

Deleting

# We can remove the boilerplate code and get straight to the method
from aiob2 import bucket

await bucket.delete_file(
    file_name='home.jpeg',
    file_id='4_z275c6d8d808e543872cc0215_f11088ad8814ee120_d20220514_m211709_c002_v0001096_t0019_u01652563029709',
    conn_info=conn_info,
    session=s
)

This will return a DeletedFile object, it has the following attributes:

file_name
file_id

License


This project is released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiob2-0.1.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiob2-0.1.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file aiob2-0.1.2.tar.gz.

File metadata

  • Download URL: aiob2-0.1.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for aiob2-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b70a33ed250a0034d3b90213f12016aa4fc9f608500eadc09a7732f6ed941b52
MD5 9a88f438b564339adeb5783ed5c30e39
BLAKE2b-256 1a6d80125d280ba386a49201a95b78c867e39a98b2e2831840bc1875ce079c36

See more details on using hashes here.

File details

Details for the file aiob2-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aiob2-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for aiob2-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be12f06b158c2ab98f2daf1d1aef2de27f7db01792db0dd858d700669c2819d1
MD5 da88e364985509324ece0937b433dd88
BLAKE2b-256 53e192888305c849e23d674bf52041838cf6e4bee894b5781e78e380f1412fb7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page