Simplified S3 storage backends for Django projects with intelligent bucket and region selection.
Project description
django-smart-storages
Reusable, specialized storage backends built on top of django-storages
This package provides a simple, consistent way to define multiple custom S3 or file storage backends in Django projects — each with its own configuration, bucket, or logic — without repeating boilerplate code.
Features
Clean abstraction for per-use-case S3 buckets Seamless integration with django-storages Built-in backend resolver for dynamic imports Optional fallback to local storage in development Easy to extend for any specialized storage use case
Installation
pip install django-special-storages
Configuration
In your Django settings, add the relevant apps:
# settings.py
INSTALLED_APPS = [
'storages', # this is for django-storages
]
Example: Custom Storage Classes
Define specialized storage classes in your code (e.g., views.py or a separate storages.py):
# views.py (or storages.py)
from smart_storages import BaseSpecialS3Storage
class ImportExportS3Storage(BaseSpecialS3Storage):
storage_key = "import_export"
class AnalyticsS3Storage(BaseSpecialS3Storage):
storage_key = "analytics"
Example: Configuring Multiple Storages
Add your bucket names and the STORAGES setting:
# settings.py
AWS_STORAGE_BUCKET_NAME = "main-bucket"
STORAGES = {
# Default file storage
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
# Static files
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
# Import-export-specific S3 storage (using your custom base class)
"import_export": {
"BACKEND": "special_storages.s3.ImportExportS3Storage",
"OPTIONS": {
"custom_domain": None,
"querystring_auth": True,
},
},
# Analytics-specific S3 storage
"analytics": {
"BACKEND": "special_storages.s3.AnalyticsS3Storage",
"OPTIONS": {
"custom_domain": None,
},
},
}
Example 1: Saving directly to S3 via FileField
This will automatically use the given bucket configured in ImportExportS3.
class PublicImage(models.Model):
file = models.FileField(storage=ImportExportS3())
Example 2: Saving a file via model's save() method
Useful if you need to process or manipulate the file before uploading.
class PublicImage(models.Model):
file = models.FileField()
def save(self, *args, **kwargs):
# Only upload if a file is provided
if self.file and hasattr(self.file, 'file'):
storage = ImportExportS3()
# Save file content to S3
saved_name = storage.save(self.file.name, self.file)
# Update the file name to the S3 path
self.file.name = saved_name
super().save(*args, **kwargs)
Example 3: Uploading a file from a remote URL (binary download or streaming)
Useful for fetching external content and storing it directly in S3.
import requests
from django.core.files.base import ContentFile
class PublicImage(models.Model):
image = models.URLField(blank=True, null=True)
def save(self, *args, **kwargs):
# Fetch an image from a remote URL
image_url = "https://www.edx.org/contentful/ii9ehdcj88bc/2SkUwC7Kf9G5I5b49hjVgu/1fa2453e92e46d980f9f99cf08a51e73/image_processing.jpg?w=435&h=245&fm=webp"
response = requests.get(image_url)
if response.status_code == 200:
# Wrap content in Django ContentFile
content = ContentFile(response.content)
# Use custom S3 storage to save
storage = ImportExportS3()
file_name = storage.save("deb.png", content)
# Update the model field with the S3 URL
self.image = storage.url(file_name)
# Save model instance
super().save(*args, **kwargs)
Note:
You can place these custom storage classes in any appropriate module (such asstorages.py), and reference them in yourSTORAGESDjango setting.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_smart_storages-0.1.0.tar.gz.
File metadata
- Download URL: django_smart_storages-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dd20a8b3bc261366f9e7a29a41f39b52104ffa7c17587da15288e979a0748e2
|
|
| MD5 |
8e426b5bd53d7ad41f27f33be4d772aa
|
|
| BLAKE2b-256 |
f3b6193657eb2b11c4a90d2bb4512adafb49f5345e91d968933618a92e9eeb82
|
Provenance
The following attestation bundles were made for django_smart_storages-0.1.0.tar.gz:
Publisher:
pypi-publish.yml on awais786/django-smart-storages
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_smart_storages-0.1.0.tar.gz -
Subject digest:
3dd20a8b3bc261366f9e7a29a41f39b52104ffa7c17587da15288e979a0748e2 - Sigstore transparency entry: 618942068
- Sigstore integration time:
-
Permalink:
awais786/django-smart-storages@8206ecabf7dff4a4b4829b7631066e816070f749 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/awais786
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@8206ecabf7dff4a4b4829b7631066e816070f749 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file django_smart_storages-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_smart_storages-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8dd533a9f186563a255106301a87154ddc68a6f1ff25341ed01ac9afb743783
|
|
| MD5 |
0e69cbcf6fd90324ecfdbd0855616377
|
|
| BLAKE2b-256 |
c16ea895e8e49a26ce0e2be9a5e463bf148c324014ba14eb7dfbf9fb8376c7c9
|
Provenance
The following attestation bundles were made for django_smart_storages-0.1.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on awais786/django-smart-storages
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_smart_storages-0.1.0-py3-none-any.whl -
Subject digest:
a8dd533a9f186563a255106301a87154ddc68a6f1ff25341ed01ac9afb743783 - Sigstore transparency entry: 618942075
- Sigstore integration time:
-
Permalink:
awais786/django-smart-storages@8206ecabf7dff4a4b4829b7631066e816070f749 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/awais786
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@8206ecabf7dff4a4b4829b7631066e816070f749 -
Trigger Event:
workflow_dispatch
-
Statement type: