django-minio-backend
The django-minio-backend provides a wrapper around the MinIO Python SDK. See minio/minio-py for the source.
Integration
- Get and install the package:
pip install django-minio-backend
- Add
django_minio_backendtoINSTALLED_APPS:
INSTALLED_APPS = [
# '...'
'django_minio_backend', # https://github.com/theriverman/django-minio-backend
]
If you would like to enable on-start consistency check, install via DjangoMinioBackendConfig:
INSTALLED_APPS = [
# '...'
'django_minio_backend.apps.DjangoMinioBackendConfig', # https://github.com/theriverman/django-minio-backend
]
Then add the following parameter to your settings file:
MINIO_CONSISTENCY_CHECK_ON_START = True
Note: The on-start consistency check equals to manually calling python manage.py initialize_buckets.
It is recommended to turn off this feature during development by setting MINIO_CONSISTENCY_CHECK_ON_START to False,
because this operation can noticeably slow down Django's boot time when many buckets are configured.
- Add the following parameters to your
settings.py:
from datetime import timedelta
from typing import List, Tuple
MINIO_ENDPOINT = 'minio.your-company.co.uk'
MINIO_ACCESS_KEY = 'yourMinioAccessKey'
MINIO_SECRET_KEY = 'yourVeryS3cr3tP4ssw0rd'
MINIO_USE_HTTPS = True
MINIO_URL_EXPIRY_HOURS = timedelta(days=1) # Default is 7 days (longest) if not defined
MINIO_CONSISTENCY_CHECK_ON_START = True
MINIO_PRIVATE_BUCKETS = [
'django-backend-dev-private',
]
MINIO_PUBLIC_BUCKETS = [
'django-backend-dev-public',
]
MINIO_POLICY_HOOKS: List[Tuple[str, dict]] = []
- Implement your own Attachment handler and integrate django-minio-backend:
from django.db import models
from django_minio_backend import MinioBackend, iso_date_prefix
class PrivateAttachment(models.Model):
file = models.FileField(verbose_name="Object Upload",
storage=MinioBackend(bucket_name='django-backend-dev-private'),
upload_to=iso_date_prefix)
- Initialize the buckets & set their 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 fromprivate(default) topublic.
python manage.py initialize_buckets
Code reference: initialize_buckets.py.
Health Check
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() # An empty string is fine this time
if minio_available:
print("OK")
else:
print("NOK")
print(minio_available.details)
Policy Hooks
You can configure django-minio-backend to automatically execute a set of pre-defined policy hooks.
Policy hooks can be defined in settings.py by adding MINIO_POLICY_HOOKS which must be a list of tuples.
Policy hooks are automatically picked up by the initialize_buckets management command.
For an exemplary policy, see the implementation of def set_bucket_to_public(self)
in django_minio_backend/models.py or the contents
of examples/policy_hook.example.py.
Consistency Check On Start
When enabled, the initialize_buckets management command gets called automatically when Django starts.
This command connects to the configured minIO server and checks if all buckets defined in settings.py.
In case a bucket is missing or its configuration differs, it gets created and corrected.
Reference Implementation
For a reference implementation, see Examples.
Compatibility
- Django 2.2 or later
- Python 3.6.0 or later
- MinIO SDK 7.0.2 or later
Note: This library relies heavily on PEP 484 -- Type Hints which was introduced in Python 3.5.0.
Contribution
Please find the details in CONTRIBUTE.md
Copyright
- theriverman/django-minio-backend licensed under the MIT License
- minio/minio-py is licensed under the Apache License 2.0
Metadata
Release files for django-minio-backend 2.6.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 | Provenance | Actions |
|---|---|---|---|---|
| django-minio-backend-2.6.0.tar.gz | 18.7 kB | Without provenance | Details for django-minio-backend-2.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_minio_backend-2.6.0-py3-none-any.whl | Python 3 | none | any | Details for django_minio_backend-2.6.0-py3-none-any.whl |
Total release size: 39.8 kB
Release files / django-minio-backend-2.6.0.tar.gz
| Download URL | django-minio-backend-2.6.0.tar.gz |
|---|---|
| Size | 18.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c118c51706db5bd3dc4796dfa44331dd0c3e81e3905ea1fc430e4d915d24bf92
|
|
BLAKE2b-256 checksum How to use checksums |
54eb6169a82796bcf46a9beb3ab372ff8f6378042b9a09655ab102df15c501df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
|
Release files / django_minio_backend-2.6.0-py3-none-any.whl
| Download URL | django_minio_backend-2.6.0-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf4dcb3c9b06341addeb6156e996bb0cd941cfad0ac59f774c134bef16d32eae
|
|
BLAKE2b-256 checksum How to use checksums |
ce74c4f5abed7bad7c68bab9a3802b3553e2495a7a1542e1101de9dc2b73f449
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
|
Security for django-minio-backend 2.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.