Skip to main content

This Python package provides a Django storage implementation that uses a single database table.

Django developers may find this package to be most helpful for use in their test and prototype environments. This package may also be useful in launching small-scale projects/environments quickly without needing additional infrastructure setup.

WARNING: For production applications, please consider using a CDN instead of this package, as it is not a good practice to serve files from a database. Website performance will suffer! Please see the section "Alternatives" below for performant and scalable storage options.

Features / Benefits

  • Easy to install and configure.
  • Serve files properly when there are multiple django servers under a load balancer.
  • Files persist in database when application server is rebuilt (as long as database is not hosted on the application server).
  • In unit testing scenarios, created files can be automatically "rolled back" out of existence if the unit test uses a transaction, which is how django.test.TestCase works.

Installation

pip install django-single-table-db-storage

Setup

In your django settings file, add 'django_single_table_db_storage' to INSTALLED_APPS.

INSTALLED_APPS = [
    ...
    'django_single_table_db_storage',
    ...
]

Also in your django settings file, set up the default storage. It is recommended that you add a TODO to remind yourself to use a better storage in the future.

# TODO: As this project scales, a CDN or S3-compatible storage for production
#       might be a better solution.
DEFAULT_FILE_STORAGE = 'django_single_table_db_storage.storage.SingleTableDbFileStorage'

In your django settings file, you should determine the default accesibility of the files that are uploaded.

DJANGO_SINGLE_TABLE_DEFAULT_PUBLIC = True  # or set it to False. The default is False.

Mount the URLs where you want in your urls.py file.

urlpatterns = [
    ... 
    path('files/', include('django_single_table_db_storage.urls')),
    ....
]

Run the database migrations to create the table.

./manage.py migrate

...And now your environment is set to use the file storage.

Alternatives

You can find other file storage alternatives for Django here:

https://djangopackages.org/grids/g/storage-backends/

This package contains a similar and possibly better implementation to this library, depending on your use case and license that you prefer:

https://github.com/kimetrica/django-binary-database-files/

Metadata

Release files for django-single-table-db-storage 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-single-table-db-storage 0.1.3
File Size Uploaded
django-single-table-db-storage-0.1.3.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-single-table-db-storage 0.1.3
File Interpreter ABI Platform
django_single_table_db_storage-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / django-single-table-db-storage-0.1.3.tar.gz

Download URL django-single-table-db-storage-0.1.3.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
41a4ef6122ab2ff531ef55919447529b0645314e57c8af0063c6cc880a58f454
BLAKE2b-256 checksum
How to use checksums
b7613ce318f2bbbed5998e2f84e9001bf60281c5a0091e4371d6705cbdada7b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / django_single_table_db_storage-0.1.3-py3-none-any.whl

Download URL django_single_table_db_storage-0.1.3-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a6e6e9b447ff10ba69885dadc40d4039461e887022f5553301d36cbcfb0eca8
BLAKE2b-256 checksum
How to use checksums
79b5c20a2583b25a04cb66cc5b1961b86fc81ea4a6992d16613c75bc7e788ea5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page