Skip to main content

django backblaze b2 storage using b2sdk

Project description

django backblaze b2 storage using b2sdk (b2sdk is official backblaze python library)


The full documentation is at


Install django-b2:

pip install django-b2

Add into your settings:

MEDIA_URL = '/media/'
DEFAULT_FILE_STORAGE = ''                 # if used without django-tenant-schemas
# DEFAULT_FILE_STORAGE = 'django_b2.tenant_storage.TenantB2Storage'  # if used with django-tenant-schemas
# optional, see Usage:
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)
with open(filename, 'rb') as f:
    b2.upload_file(filename, f)
content = b2.download_file(filename)
with open(filename2, 'wb') as f:


  • Django media storage (with or general python access to BackBlaze B2 (without usage of
  • Upload single file to B2 (call as script; new in 0.2.0)
  • Backup a postgres database to B2 (use script; 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


Tools used in rendering this package:


0.5.3 (2020-05-24)

  • bugfix: upload on Windows, thx Same Weaver,
  • 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)

  • can be called as script to upload single file.
  • 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.

Project details

Download files

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

Files for django-b2, version 0.5.3
Filename, size File type Python version Upload date Hashes
Filename, size django_b2-0.5.3-py2.py3-none-any.whl (13.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size django-b2-0.5.3.tar.gz (15.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page