django-storages-dospaces
Small wrapper over django-storages S3Boto3Storage with sane defaults for DigitalOcean Spaces usage.
Installation via pip
pip install django-storages-dospaces
Usage
In order to use django-storages-dospaces all you need to do is to set it's backend as your default STATICFILES_STORAGE on your project's settings.py file and configure some settings on it. It's recommended to use environment variables to achieve it.
Environment variables
The following environment variables must be set in order to use this package with your DigitalOcean Space.
DO_SPACES_ENDPOINT_URL must point to your Space server region, eg: if your space is on sfo2, the URL should be https://sfo2.digitaloceanspaces.com
DO_SPACES_ACCESS_KEY_ID='<your Space id >'
DO_SPACES_CACHE_MAX_AGE='86400'
DO_SPACES_DEFAULT_ACL='None'
DO_SPACES_ENDPOINT_URL='https://<region>.digitaloceanspaces.com'
DO_SPACES_SECRET_ACCESS_KEY='<your Space access key>'
DO_SPACES_SPACE_FOLDER='<the folder where your files will be uploaded to>'
DO_SPACES_SPACE_NAME='<the name of your Space as it appears in your dashboard>'
You can set them using an script with export command before every line(if using bash) or another way of your preference.
Once they are set, they can be gotten from your settings.py file using os.environ.get('<env var key>')
Settings file
In order to enable this package behaviour you will have to set the following settings on your project's settings.py file
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
# Definitive configuration
DO_SPACES_ACCESS_KEY_ID = os.environ.get(
'DO_SPACES_ACCESS_KEY_ID'
)
DO_SPACES_SECRET_ACCESS_KEY = os.environ.get(
'DO_SPACES_SECRET_ACCESS_KEY'
)
DO_SPACES_SPACE_NAME = os.environ.get(
'DO_SPACES_SPACE_NAME'
)
DO_SPACES_SPACE_FOLDER = os.environ.get(
'DO_SPACES_SPACE_FOLDER'
)
DO_SPACES_ENDPOINT_URL = os.environ.get(
'DO_SPACES_ENDPOINT_URL'
)
DO_SPACES_CACHE_MAX_AGE = int(
os.environ.get(
'DO_SPACES_CACHE_MAX_AGE',
86400
)
)
DO_SPACES_DEFAULT_ACL = None
# Get DEFAULT_ACL from env vars
try:
DEFAULT_ACL = os.environ.get(
'DO_SPACES_DEFAULT_ACL'
)
if DEFAULT_ACL != 'None':
DO_SPACES_DEFAULT_ACL = DEFAULT_ACL
except Exception as e:
pass
# Set File locations
DO_SPACES_STATIC_LOCATION = '{FOLDER}/static'.format(
FOLDER=DO_SPACES_SPACE_FOLDER
)
DO_SPACES_PUBLIC_MEDIA_LOCATION = '{FOLDER}/media/public'.format(
FOLDER=DO_SPACES_SPACE_FOLDER
)
DO_SPACES_PRIVATE_MEDIA_LOCATION = '{FOLDER}/media/private'.format(
FOLDER=DO_SPACES_SPACE_FOLDER
)
# Static files config
STATIC_URL = 'https://{ENDPOINT_URL}/{STATIC_LOCATION}/'.format(
ENDPOINT_URL=DO_SPACES_ENDPOINT_URL,
STATIC_LOCATION=DO_SPACES_STATIC_LOCATION
)
# Configure file storage settings
STATICFILES_STORAGE = 'storages-dospaces.backends.do_spaces.DigitalOceanSpacesStaticStorage'
DEFAULT_FILE_STORAGE = 'storages-dospaces.backends.do_spaces.DigitalOceanSpacesPublicMediaStorage'
PRIVATE_FILE_STORAGE = 'storages-dospaces.backends.do_spaces.DigitalOceanSpacesPrivateMediaStorage'
Metadata
Release files for django-storages-dospaces 0.1.1
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-storages-dospaces-0.1.1.tar.gz | 15.2 kB | Without provenance | Details for django-storages-dospaces-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_storages_dospaces-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for django_storages_dospaces-0.1.1-py3-none-any.whl |
Total release size: 30.8 kB
Release files / django-storages-dospaces-0.1.1.tar.gz
| Download URL | django-storages-dospaces-0.1.1.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d8e6025f1e567af64d50fc9c45680b093065d18b43c5c7af71f5dad99ff7c5d4
|
|
BLAKE2b-256 checksum How to use checksums |
c67c176b770095b6963994c20344a3a168763aff056d641fdd9ce5cc7e5190a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.6 Linux/5.8.0-7630-generic
|
Release files / django_storages_dospaces-0.1.1-py3-none-any.whl
| Download URL | django_storages_dospaces-0.1.1-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
017da218b89e3972fb8ea1d01625f6b613c94f8070a594dfeff63bdbad5476ac
|
|
BLAKE2b-256 checksum How to use checksums |
9127be568690617ed26aa02fb57b2247037ca6d9ab04d6c869baba7bedf0df2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.6 Linux/5.8.0-7630-generic
|
Security for django-storages-dospaces 0.1.1
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.