Skip to main content

Application settings helper for Django apps.

Project description

Django AppSettings

Application settings helper for Django apps.

Why another app settings app? Because none of the other suited my needs!

This one is simple to use, and works with unit tests overriding settings.

Usage

With recent Django versions, it is recommended to put your settings in an apps.py module of your Django app, though you can put it wherever you want. The following is just an example.

from django.apps import AppConfig
import appsettings as aps

class MyAppConfig(AppConfig):
    name = 'my_app'
    verbose_name = 'My Application'

    def ready(self):
        AppSettings.check()


class AppSettings(aps.AppSettings):
    always_use_ice_cream = aps.BooleanSetting(default=True)
    attr_name = aps.StringSetting(name='SETTING_NAME')

    # if you have complex treatment to do on setting
    complex_setting = aps.Setting(transformer=custom_method, checker=custom_checker)

    # if you need to import a python object (module/class/method)
    imported_object = aps.ImportedObjectSetting(default='app.default.object')

    class Meta:
        setting_prefix = 'ASH'  # settings must be prefixed with ASH

Then in other modules:

from .apps import AppSettings

# instantiation will load and transform every settings
app_settings = AppSettings()
app_settings.attr_name == 'something'

# or, and in order to work with tests overriding settings
AppSettings.get_always_use_ice_cream()  # to get ASH_ALWAYS_USE_ICE_CREAM setting dynamically
my_python_object = AppSettings.get_imported_object()

You can access settings directly from the settings class, but also from the settings instances:

my_setting = AppSettings.my_setting
my_setting.get()  # get and transform
my_setting.check()  # get and check
my_setting.get_raw()  # just get the value in django settings

Running AppSettings.check() will raise an ImproperlyConfigured exception if at least one of the settings’ check methods raised an exception. It will also print all caught exceptions.

License

Software licensed under ISC license.

Installation

pip install django-app-settings

Documentation

On ReadTheDocs

Development

To run all the tests: tox

Changelog

0.1.0 (2017-03-23)

  • Alpha release on PyPI.

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-app-settings-0.2.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

django_app_settings-0.2.0-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-app-settings-0.2.0.tar.gz.

File metadata

File hashes

Hashes for django-app-settings-0.2.0.tar.gz
Algorithm Hash digest
SHA256 42e780b0f6d8a4118974d83d3cdb3c4731efa4dc52fa1e93a6fa3cfeccd4446d
MD5 3c1aa21fe31ded95514ddef743de34de
BLAKE2b-256 b91a9d89d92b9a8abcfe1f2bb386e93e23f1dfd40dc11b3ceec28a03b74d3fa3

See more details on using hashes here.

File details

Details for the file django_app_settings-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_app_settings-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c302eb5a71e225dd2b6da1ff3c60397d0225564a3a81f6ecb764b5463dd7878f
MD5 b1cf61971f6c5c48cde39b947c08f6f8
BLAKE2b-256 7593739063c0fd803a43c02a8a1bab5690c4f812e2ca8d0a38e59f165876d764

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