The django-minio-backend provides a wrapper around the
MinIO Python SDK.
-
Get and install the package:
pip install django-minio-backend -
Add
django_minio_backendtoINSTALLED_APPS:
INSTALLED_APPS = [
'...'
'django_minio_backend', # django-minio-backend | https://github.com/theriverman/django-minio-backend
]- Add the following parameters to your
settings.py:
from datetime import timedelta
MINIO_ENDPOINT = 'minio.yourcompany.co.uk'
MINIO_ACCESS_KEY = 'yourMinioAccessKey'
MINIO_SECRET_KEY = 'yourVeryS3cr3tP4ssw0rd'
MINIO_USE_HTTPS = True
MINIO_PRIVATE_BUCKET_NAMES = ['my-app-private']
MINIO_PUBLIC_BUCKET_NAMES = ['my-app-public']
MINIO_URL_EXPIRY_HOURS = timedelta(days=1)The first element of MINIO_PUBLIC_BUCKET_NAMES or MINIO_PRIVATE_BUCKET_NAMES is the default bucket that will
be used when you use just the is_public flag.
- Implement your own Attachment handler and integrate django-minio-backend:
from django.db import models
from django_minio_backend import MinioBackend, iso_date_prefix
# noinspection PyUnresolvedReferences
class PrivateAttachment(models.Model):
file = models.FileField(verbose_name="Object Upload", storage=MinioBackend(is_public=False),
upload_to=iso_date_prefix)-
Initialize buckets & set public policy (OPTIONAL):
Thisdjango-admincommand creates both the private and public buckets in case one of them does not exists and sets the public bucket's privacy policy from private(default) to public.
python manage.py initialize_bucketsCode reference: initialize_buckets.py.
To check the connection link between Django and MinIO, use the provided MinioBackend.is_minio_available() method.
It returns a MinioServerStatus instance which can be quickly evaluated as boolean.
Example:
from django_minio_backend import MinioBackend
minio_available = MinioBackend().is_minio_available()
if minio_available:
print("OK")
else:
print("NOK")
print(minio_available.details)For a reference implementation, see Examples.
- Django 2.0 or later
- Python 3.5.0 or later
Note: This library relies heavily on PEP 484 -- Type Hints which was introduced in Python 3.5.0.
To build a new package, execute the following command:
python setup.py sdist
- theriverman/django-minio-backend licensed under the MIT License
- minio/minio-py is licensed under the Apache License 2.0