Skip to main content

Allow for more complex and dynamic settings for Django

Project description

django-enhanced-settings

Tests codecov PyPI PyPI - Python Version PyPI - Wheel

Allow for more complex and dynamic settings for Django.

Extras

cloud-secret-manager - Adds support for Google Cloud Secret Manager

Example

import os

from django_enhanced_settings import Settings


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

settings = Settings(BASE_DIR)


def __dir__():
    return settings.dir(globals())


def __getattr__(name):
    return settings.getattr(name, globals())


_DEBUG = settings.boolean_value('DJANGO_DEBUG', False)
_ALLOWED_HOSTS = settings.list_value(
    'DJANGO_ALLOWED_HOSTS',
    ['localhost'] if _DEBUG.value else [],
    split_char=';'
)
_SECRET_KEY = settings.string_value('DJANGO_SECRET_KEY', required=True)
INSTALLED_APPS = [...]
from django.conf import setings

settings.DEBUG  # By default returns False

Rules

  1. You are not allowed to name a non ConfigValue using the naming scheme set for the Settings instance (suffix_underscore). For example, writing the following would raise a ValueError in the above example:
_INSTALLED_APPS = [...]
  1. You are not allowed to name a ConfigValue without using the naming scheme set for the Settings instance (suffix_underscore). For example, writing the following would raise a ValueError in the above example:
SECRET_KEY = settings.string_value('DJANGO_SECRET_KEY', required=True)
  1. You are not allowed to define 2 variable names that result in the same accessible name. For example, writing the following would raise a ValueError in the above example:
_SECRET_KEY = settings.string_value('DJANGO_SECRET_KEY', required=True)
SECRET_KEY = 'SECRET_KEY'

If you would like to customise these rules you can write your own __dir__ and __getattr__.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-enhanced-settings-0.2.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

django_enhanced_settings-0.2.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file django-enhanced-settings-0.2.1.tar.gz.

File metadata

  • Download URL: django-enhanced-settings-0.2.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.0.0-1032-azure

File hashes

Hashes for django-enhanced-settings-0.2.1.tar.gz
Algorithm Hash digest
SHA256 dca0dd41cadd3c2bfd7bba241e15d8e88b565c69cb268f0a4e0c621b94863565
MD5 49427090c04d964b563c619de3bf73c7
BLAKE2b-256 5466d3767fbcdaaef190047c3da4127394a93ff4debf0b724d85763f2215a231

See more details on using hashes here.

File details

Details for the file django_enhanced_settings-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_enhanced_settings-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff45e5340d5b0d97c7d853a5d6c51fd4221f954581011c48305ca7895e05749b
MD5 9967ea241e0ce3733edfad7e98cd3ba0
BLAKE2b-256 74499277bfe53e64c3b24c3f8a0777c354b725856b6982c9b7844f3b307e50d5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page