django-app-settings


Namedjango-app-settings JSON
Version 0.7.2 PyPI version JSON
download
home_pagehttps://github.com/pawamoy/django-appsettings
SummaryApplication settings helper for Django apps.
upload_time2023-09-07 13:30:41
maintainer
docs_urlNone
authorTimothee Mazzucotelli
requires_python~=3.5
licenseISC
keywords django app settings
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ==================
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.

Installation
============

::

    pip install django-app-settings

Documentation
=============

`On ReadTheDocs`_

.. _`On ReadTheDocs`: http://django-appsettings.readthedocs.io/

Development
===========

To run all the tests: ``tox``. See `CONTRIBUTING`_.

.. _`CONTRIBUTING`: https://github.com/pawamoy/django-appsettings/blob/master/CONTRIBUTING.rst

Quick usage
===========

.. code:: python

    # Define your settings class
    import appsettings


    class MySettings(appsettings.AppSettings):
        boolean_setting = appsettings.BooleanSetting(default=False)
        required_setting = appsettings.StringSetting(required=True)
        named_setting = appsettings.IntegerSetting(name='integer_setting')
        prefixed_setting = appsettings.ListSetting(prefix='my_app_')

        class Meta:
            setting_prefix = 'app_'


    # Related settings in settings.py
    APP_INTEGER_SETTING = -24
    MY_APP_PREFIXED_SETTING = []


    # Instantiate your class wherever you need to
    appconf = MySettings()
    assert appconf.boolean_setting is False  # True (default value)
    assert appconf.required_setting == 'hello'  # raises AttributeError
    assert appconf.named_setting < 0  # True
    assert appconf.prefixed_setting  # False (empty list)


    # Values are cached to avoid perf issues
    with override_settings(APP_REQUIRED_SETTING='hello',
                           APP_INTEGER_SETTING=0):
        # ...but cache is cleaned on Django's setting_changed signal
        assert appconf.required_setting == 'hello'  # True
        assert appconf.named_setting < 0  # False


    # You can still access settings through the class itself (values not cached)
    print(MySettings.boolean_setting.get_value())  # explicit call
    print(MySettings.boolean_setting.value)  # with property


    # Run type checking and required presence on all settings at once
    MySettings.check()  # raises Django's ImproperlyConfigured (missing required_setting)
    # MySettings.check() is best called in django.apps.AppConfig's ready method


You can easily create your own Setting classes for more complex settings.

.. code:: python

    import re

    import appsettings
    from django.core.exceptions import ValidationError


    class RegexSetting(appsettings.Setting):
        def validate(self, value):
            re_type = type(re.compile(r'^$'))
            if not isinstance(value, (re_type, str)):
                # Raise ValidationError
                raise ValidationError('Value must be a string or a compiled regex (use re.compile)')

        def transform(self, value):
            # ensure it always returns a compiled regex
            if isinstance(value, str):
                value = re.compile(value)
            return value


Please check the documentation to see even more advanced usage.

License
=======

Software licensed under `ISC`_ license.

.. _ISC: https://www.isc.org/downloads/software-support-policy/isc-license/


=========
Changelog
=========

Unreleased
==========


0.7.2 (2023-09-07)
==================

- Deprecate loding setting values from environment (#98 by @stinovlas)
- Fix optional nested dict setting (#92 by @rastytheamateur)
- Fix typos in ``usage.rst`` (#102 by @oto-stefan)
- Fix docs build (#100 by @stinovlas)

0.7.1 (2020-05-28)
==================

- Ignore environment variables when using ``override_settings``.
- Don't announce type annotations.

0.7.0 (2020-04-14)
==================

- Read setting values from environment variables.
- Add ``FileSetting``.
- Fix bug causing ``NestedDictSetting`` to be always required.
- Add support for python 3.8 and Django 3.0.
- Drop support for python 2.7 and 3.4.
- Drop deprecated type checkers.
- Add type annotations.
- Raise ``ImproperlyConfigured`` from ``Setting.check`` for all errors in a setting.
- Move repository to https://github.com/pawamoy/django-appsettings.
- Clean tests.

0.6.1 (2020-03-04)
==================

- Fix ``transform_default`` in ``NestedListSetting``, by @stinovlas (see PR `#61`_).

.. _#61: https://github.com/pawamoy/django-appsettings/issues/61

0.6.0 (2019-08-27)
==================

- Add ``CallablePathSetting`` (see issue `#49`_ and PR `#52`_).
- Add ``NestedListSetting`` (see issue `#50`_ and PR `#53`_).
- Rename ``NestedSetting`` to ``NestedDictSetting`` (old name is still available but deprecated).

.. _#49: https://github.com/pawamoy/django-appsettings/issues/49
.. _#50: https://github.com/pawamoy/django-appsettings/issues/50
.. _#52: https://github.com/pawamoy/django-appsettings/issues/52
.. _#53: https://github.com/pawamoy/django-appsettings/issues/53

0.5.1 (2019-05-23)
==================

- Fix default values for empty arguments.

0.5.0 (2018-12-03)
==================

- Deprecate setting checkers in favor of validators, similarly to Django form fields.

0.4.0 (2018-07-25)
==================

- Add ``NestedSetting`` for easy management of nested settings.

0.3.0 (2017-11-30)
==================

Going from alpha to beta status. Logic has been reworked.

- An instance of a subclass of ``AppSettings`` will now dynamically get
  settings values from project settings, and cache them. This allows to use
  the instance the same way in code and tests, without performance loss. See
  issue `#16`_.
- Cache is invalidated when Django sends a ``setting_changed`` signal (i.e.
  when using ``TestCase`` or ``override_settings``). See issue `#16`_.
- Setting main class now accepts callable as default value, and two new
  parameters to keep control on its behavior: ``call_default``, which tells
  if the default value should be called (if callable) or not, and
  ``transform_default``, which tells if the default value should be transformed
  as well by the ``transform`` method. See issue `#17`_.
- Settings type checkers now have custom parameters like ``max_length``,
  ``empty`` or ``key_type``, that can be passed directly through the settings
  classes as keyword arguments. Check the documentation for more information.
- Settings classes have been rewritten more explicitly, using class inheritance
  instead of hard-to-debug generators. Composed types like float lists or
  boolean sets have been removed in favor of more flexible list, set and tuple
  types which now accept an optional ``item_type`` parameter.
- ``ImportedObjectSetting`` has been renamed ``ObjectSetting``, and now
  supports object paths down to arbitrary level of nesting. Before, it only
  supported object paths down to classes or functions, now you can for example
  give it the path to a constant in a class within a class, itself contained
  in a module within a package. It will work as long a the deepest module is
  importable through ``importlib.import_module`` and each object down to the
  last is obtainable through ``getattr`` method.

Many thanks to `ziima`_ for having shared good ideas and thoughts!

.. _#16: https://github.com/pawamoy/django-appsettings/issues/16
.. _#17: https://github.com/pawamoy/django-appsettings/issues/17
.. _ziima: https://github.com/ziima

0.2.5 (2017-06-02)
==================

- Add six dependency (now required).
- Rename ``Int`` settings to ``Integer``, and ``Bool`` ones to ``Boolean``.
- Remove metaclass generated getters and checkers.

0.2.4 (2017-05-02)
==================

- Settings are not checked when they default to the provided default value.
- Settings classes received better default values corresponding to their types.

0.2.3 (2017-05-02)
==================

- Add ``full_name`` property to ``Setting`` class.
- Add ``required`` parameter to ``Setting`` class (default ``False``).

0.2.2 (2017-04-17)
==================

- Import settings classes in main module to simplify imports.

0.2.1 (2017-04-17)
==================

- Add ``PositiveInt`` and ``PositiveFloat`` settings.
- Add support for Django 1.11.
- Implement basic settings classes.

0.2.0 (2017-04-17)
==================

- Implement basic Setting class.
- Pin dependencies.
- Change distribution name to ``app-settings``.

0.1.0 (2017-03-23)
==================

- Alpha release on PyPI.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pawamoy/django-appsettings",
    "name": "django-app-settings",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "~=3.5",
    "maintainer_email": "",
    "keywords": "django,app,settings",
    "author": "Timothee Mazzucotelli",
    "author_email": "timothee.mazzucotelli@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c4/27/7141e90d1e4984722a5d0dc0c50203bdc14832a58e481cd89f2a1c87652d/django-app-settings-0.7.2.tar.gz",
    "platform": null,
    "description": "==================\nDjango AppSettings\n==================\n\n\n\nApplication settings helper for Django apps.\n\nWhy another *app settings* app?\nBecause none of the other suited my needs!\n\nThis one is simple to use, and works with unit tests overriding settings.\n\nInstallation\n============\n\n::\n\n    pip install django-app-settings\n\nDocumentation\n=============\n\n`On ReadTheDocs`_\n\n.. _`On ReadTheDocs`: http://django-appsettings.readthedocs.io/\n\nDevelopment\n===========\n\nTo run all the tests: ``tox``. See `CONTRIBUTING`_.\n\n.. _`CONTRIBUTING`: https://github.com/pawamoy/django-appsettings/blob/master/CONTRIBUTING.rst\n\nQuick usage\n===========\n\n.. code:: python\n\n    # Define your settings class\n    import appsettings\n\n\n    class MySettings(appsettings.AppSettings):\n        boolean_setting = appsettings.BooleanSetting(default=False)\n        required_setting = appsettings.StringSetting(required=True)\n        named_setting = appsettings.IntegerSetting(name='integer_setting')\n        prefixed_setting = appsettings.ListSetting(prefix='my_app_')\n\n        class Meta:\n            setting_prefix = 'app_'\n\n\n    # Related settings in settings.py\n    APP_INTEGER_SETTING = -24\n    MY_APP_PREFIXED_SETTING = []\n\n\n    # Instantiate your class wherever you need to\n    appconf = MySettings()\n    assert appconf.boolean_setting is False  # True (default value)\n    assert appconf.required_setting == 'hello'  # raises AttributeError\n    assert appconf.named_setting < 0  # True\n    assert appconf.prefixed_setting  # False (empty list)\n\n\n    # Values are cached to avoid perf issues\n    with override_settings(APP_REQUIRED_SETTING='hello',\n                           APP_INTEGER_SETTING=0):\n        # ...but cache is cleaned on Django's setting_changed signal\n        assert appconf.required_setting == 'hello'  # True\n        assert appconf.named_setting < 0  # False\n\n\n    # You can still access settings through the class itself (values not cached)\n    print(MySettings.boolean_setting.get_value())  # explicit call\n    print(MySettings.boolean_setting.value)  # with property\n\n\n    # Run type checking and required presence on all settings at once\n    MySettings.check()  # raises Django's ImproperlyConfigured (missing required_setting)\n    # MySettings.check() is best called in django.apps.AppConfig's ready method\n\n\nYou can easily create your own Setting classes for more complex settings.\n\n.. code:: python\n\n    import re\n\n    import appsettings\n    from django.core.exceptions import ValidationError\n\n\n    class RegexSetting(appsettings.Setting):\n        def validate(self, value):\n            re_type = type(re.compile(r'^$'))\n            if not isinstance(value, (re_type, str)):\n                # Raise ValidationError\n                raise ValidationError('Value must be a string or a compiled regex (use re.compile)')\n\n        def transform(self, value):\n            # ensure it always returns a compiled regex\n            if isinstance(value, str):\n                value = re.compile(value)\n            return value\n\n\nPlease check the documentation to see even more advanced usage.\n\nLicense\n=======\n\nSoftware licensed under `ISC`_ license.\n\n.. _ISC: https://www.isc.org/downloads/software-support-policy/isc-license/\n\n\n=========\nChangelog\n=========\n\nUnreleased\n==========\n\n\n0.7.2 (2023-09-07)\n==================\n\n- Deprecate loding setting values from environment (#98 by @stinovlas)\n- Fix optional nested dict setting (#92 by @rastytheamateur)\n- Fix typos in ``usage.rst`` (#102 by @oto-stefan)\n- Fix docs build (#100 by @stinovlas)\n\n0.7.1 (2020-05-28)\n==================\n\n- Ignore environment variables when using ``override_settings``.\n- Don't announce type annotations.\n\n0.7.0 (2020-04-14)\n==================\n\n- Read setting values from environment variables.\n- Add ``FileSetting``.\n- Fix bug causing ``NestedDictSetting`` to be always required.\n- Add support for python 3.8 and Django 3.0.\n- Drop support for python 2.7 and 3.4.\n- Drop deprecated type checkers.\n- Add type annotations.\n- Raise ``ImproperlyConfigured`` from ``Setting.check`` for all errors in a setting.\n- Move repository to https://github.com/pawamoy/django-appsettings.\n- Clean tests.\n\n0.6.1 (2020-03-04)\n==================\n\n- Fix ``transform_default`` in ``NestedListSetting``, by @stinovlas (see PR `#61`_).\n\n.. _#61: https://github.com/pawamoy/django-appsettings/issues/61\n\n0.6.0 (2019-08-27)\n==================\n\n- Add ``CallablePathSetting`` (see issue `#49`_ and PR `#52`_).\n- Add ``NestedListSetting`` (see issue `#50`_ and PR `#53`_).\n- Rename ``NestedSetting`` to ``NestedDictSetting`` (old name is still available but deprecated).\n\n.. _#49: https://github.com/pawamoy/django-appsettings/issues/49\n.. _#50: https://github.com/pawamoy/django-appsettings/issues/50\n.. _#52: https://github.com/pawamoy/django-appsettings/issues/52\n.. _#53: https://github.com/pawamoy/django-appsettings/issues/53\n\n0.5.1 (2019-05-23)\n==================\n\n- Fix default values for empty arguments.\n\n0.5.0 (2018-12-03)\n==================\n\n- Deprecate setting checkers in favor of validators, similarly to Django form fields.\n\n0.4.0 (2018-07-25)\n==================\n\n- Add ``NestedSetting`` for easy management of nested settings.\n\n0.3.0 (2017-11-30)\n==================\n\nGoing from alpha to beta status. Logic has been reworked.\n\n- An instance of a subclass of ``AppSettings`` will now dynamically get\n  settings values from project settings, and cache them. This allows to use\n  the instance the same way in code and tests, without performance loss. See\n  issue `#16`_.\n- Cache is invalidated when Django sends a ``setting_changed`` signal (i.e.\n  when using ``TestCase`` or ``override_settings``). See issue `#16`_.\n- Setting main class now accepts callable as default value, and two new\n  parameters to keep control on its behavior: ``call_default``, which tells\n  if the default value should be called (if callable) or not, and\n  ``transform_default``, which tells if the default value should be transformed\n  as well by the ``transform`` method. See issue `#17`_.\n- Settings type checkers now have custom parameters like ``max_length``,\n  ``empty`` or ``key_type``, that can be passed directly through the settings\n  classes as keyword arguments. Check the documentation for more information.\n- Settings classes have been rewritten more explicitly, using class inheritance\n  instead of hard-to-debug generators. Composed types like float lists or\n  boolean sets have been removed in favor of more flexible list, set and tuple\n  types which now accept an optional ``item_type`` parameter.\n- ``ImportedObjectSetting`` has been renamed ``ObjectSetting``, and now\n  supports object paths down to arbitrary level of nesting. Before, it only\n  supported object paths down to classes or functions, now you can for example\n  give it the path to a constant in a class within a class, itself contained\n  in a module within a package. It will work as long a the deepest module is\n  importable through ``importlib.import_module`` and each object down to the\n  last is obtainable through ``getattr`` method.\n\nMany thanks to `ziima`_ for having shared good ideas and thoughts!\n\n.. _#16: https://github.com/pawamoy/django-appsettings/issues/16\n.. _#17: https://github.com/pawamoy/django-appsettings/issues/17\n.. _ziima: https://github.com/ziima\n\n0.2.5 (2017-06-02)\n==================\n\n- Add six dependency (now required).\n- Rename ``Int`` settings to ``Integer``, and ``Bool`` ones to ``Boolean``.\n- Remove metaclass generated getters and checkers.\n\n0.2.4 (2017-05-02)\n==================\n\n- Settings are not checked when they default to the provided default value.\n- Settings classes received better default values corresponding to their types.\n\n0.2.3 (2017-05-02)\n==================\n\n- Add ``full_name`` property to ``Setting`` class.\n- Add ``required`` parameter to ``Setting`` class (default ``False``).\n\n0.2.2 (2017-04-17)\n==================\n\n- Import settings classes in main module to simplify imports.\n\n0.2.1 (2017-04-17)\n==================\n\n- Add ``PositiveInt`` and ``PositiveFloat`` settings.\n- Add support for Django 1.11.\n- Implement basic settings classes.\n\n0.2.0 (2017-04-17)\n==================\n\n- Implement basic Setting class.\n- Pin dependencies.\n- Change distribution name to ``app-settings``.\n\n0.1.0 (2017-03-23)\n==================\n\n- Alpha release on PyPI.\n",
    "bugtrack_url": null,
    "license": "ISC",
    "summary": "Application settings helper for Django apps.",
    "version": "0.7.2",
    "project_urls": {
        "Homepage": "https://github.com/pawamoy/django-appsettings"
    },
    "split_keywords": [
        "django",
        "app",
        "settings"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d909db382672f6d1cb99f4509b9001307550ba084637abdfcfd00bc352449d00",
                "md5": "678a56efc48559d294dea25e4c7016f4",
                "sha256": "438a3e1a9168825ad39c7e7ad1bc3c28fc17a128d117c4a702f5958abceee4fe"
            },
            "downloads": -1,
            "filename": "django_app_settings-0.7.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "678a56efc48559d294dea25e4c7016f4",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "~=3.5",
            "size": 14573,
            "upload_time": "2023-09-07T13:30:40",
            "upload_time_iso_8601": "2023-09-07T13:30:40.302771Z",
            "url": "https://files.pythonhosted.org/packages/d9/09/db382672f6d1cb99f4509b9001307550ba084637abdfcfd00bc352449d00/django_app_settings-0.7.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4277141e90d1e4984722a5d0dc0c50203bdc14832a58e481cd89f2a1c87652d",
                "md5": "def6c7a73b9e68f3712b44381953e18e",
                "sha256": "9223480aeef00dec8f89ee603454309993726b263f4f975ee7be98918c5ae27b"
            },
            "downloads": -1,
            "filename": "django-app-settings-0.7.2.tar.gz",
            "has_sig": false,
            "md5_digest": "def6c7a73b9e68f3712b44381953e18e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "~=3.5",
            "size": 35206,
            "upload_time": "2023-09-07T13:30:41",
            "upload_time_iso_8601": "2023-09-07T13:30:41.879459Z",
            "url": "https://files.pythonhosted.org/packages/c4/27/7141e90d1e4984722a5d0dc0c50203bdc14832a58e481cd89f2a1c87652d/django-app-settings-0.7.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-07 13:30:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pawamoy",
    "github_project": "django-appsettings",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "django-app-settings"
}
        
Elapsed time: 0.10278s