django backblaze b2 storage using b2sdk (b2sdk is official backblaze python library)
Documentation
The full documentation is at https://django-b2.readthedocs.io.
Quickstart
Install django-b2:
pip install django-b2
Add into your settings:
MEDIA_URL = '/media/'
DEFAULT_FILE_STORAGE = 'django_b2.storage.B2Storage' # if used without django-tenant-schemas
# DEFAULT_FILE_STORAGE = 'django_b2.tenant_storage.TenantB2Storage' # if used with django-tenant-schemas
B2_APP_KEY_ID = 000xxxxxxxxxxxx000000000n
B2_APP_KEY = keyvalue
B2_BUCKET_NAME = bucketname
# optional, see Usage (docs/usage.rst):
B2_FORCE_UNIQUE = False
# optional, see Usage (docs/usage.rst):
MEDIA_ROOT = ..
B2_LOCAL_MEDIA = .. # "", "M", "L", "ML"
Using outside of Django:
from django_b2.backblaze_b2 import BackBlazeB2
b2 = BackBlazeB2()
b2.authorize("production", application_key_id, application_key)
b2.set_bucket(bucket_name)
with open(filename, 'rb') as f:
b2.upload_file(filename, f)
content = b2.download_file(filename)
with open(filename2, 'wb') as f:
f.write(content)
Features
Django media storage (with storage.py) or general python access to BackBlaze B2 (without usage of storage.py).
Upload single file to B2 (call backblaze_b2.py as script; new in 0.2.0)
Backup a postgres database to B2 (use script pgtob2.sh; new in 0.2.0)
Optionally cache media files locally for immediate access or for long time faster access.
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install -r requirements_test.txt (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.7.0 (2020-12-29)
new Django setting B2_FORCE_UNIQUE and new underlaying constructor parameter BackBlazeB2(force_unique=True)
0.6.2 (2020-11-04)
B2Storage() initializes as the settings.DEFAULT_FILE_STORAGE if ‘B2Storage’ string is not inside can be used together with @override_settings(DEFAULT_FILE_STORAGE=’django.core.files.storage.FileSystemStorage’) see https://github.com/pyutil/django-b2/issues/4
0.6.0 (2020-05-28)
lazy loading, to avoid running code during collectstatic,.. - https://github.com/pyutil/django-b2/issues/3
0.5.5 (2020-05-24)
bugfix: upload on Windows, thx Same Weaver, https://github.com/pyutil/django-b2/issues/2
Linux abs filenames: leading “/” will be removed so we can use local abs names 1:1 to upload to b2 (in Windows: C:/.. is valid name)
0.5.0 (2020-02-17)
can work with django-tenant schemas, tenant aware storage django_b2.tenant_storage.TenantB2Storage
0.4.0 (2020-02-10)
older local media (see B2_LOCAL_MEDIA) can be cleared with management command b2_clear_local_media
B2_LOCAL_CACHE setting renamed to B2_LOCAL_MEDIA, possible values changed to =”ML”
0.3.0 (2020-02-08) - do not use
!! new B2_LOCAL_MEDIA setting was in 0.3.0 named incompatible as B2_LOCAL_CACHE=”FM”
B2_LOCAL_MEDIA setting to make a local copy of files. So you can have local instances backuped on backblaze.
B2_LOCAL_MEDIA prevents failures if the django application want immediately reopen the file (imagekits creating thumbnails, Wagtail is an example)
0.2.0 (2020-01-31)
backblaze_b2.py can be called as script to upload single file.
pgtob2.sh script to backup postgres database
0.1.5 (2020-01-02)
No code change. Minor docs changes.
0.1.4 (2020-01-02)
First release on PyPI.
Release files for django-b2 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-b2-0.7.0.tar.gz | 24.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_b2-0.7.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 90.7 kB
Release files / django-b2-0.7.0.tar.gz
| Download URL | django-b2-0.7.0.tar.gz |
|---|---|
| Size | 24.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97890435d1e4552f96552c6d2e062c99848f7bcb8a3d91944e425004e6421ba2
|
|
BLAKE2b-256 checksum How to use checksums |
ea1f312b6aa75ac405a9a2b81484a2786c8a35165d018bcf1f9b97278be3f1b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.0
|
Release files / django_b2-0.7.0-py2.py3-none-any.whl
| Download URL | django_b2-0.7.0-py2.py3-none-any.whl |
|---|---|
| Size | 66.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0601cec39fc9e37d13789b40f1a52a29307c8a67cc06241974a9dde35bf0bc0a
|
|
BLAKE2b-256 checksum How to use checksums |
e71b8d44f7f9035a79666b2821d2f4451c6a3e765f10d2e6f773f07f1fcfe100
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.0
|