Skip to main content

Helpers for dealing with application settings

Project description

COOLFIG

https://img.shields.io/travis/GaretJax/coolfig.svg https://img.shields.io/pypi/v/coolfig.svg https://img.shields.io/pypi/dm/coolfig.svg https://img.shields.io/coveralls/GaretJax/coolfig/master.svg https://img.shields.io/badge/docs-latest-brightgreen.svg https://img.shields.io/pypi/l/coolfig.svg https://img.shields.io/requires/github/GaretJax/coolfig.svg

Coolfig is a library to easily write configuration specifications to be fulfilled by various sources.

Installation

pip install coolfig

Example

Define your schema:

from coolfig import Settings, Value, types

class DefaultSettings(Settings):
     SECRET_KEY = Value(str)
     DEBUG = Value(types.boolean, default=False)
     DB_URL = Value(types.sqlalchemy_url)
     LOCALES = Value(types.list(str))

Instantiate the configuration with a data provider:

from coolfig import EnvConfig

settings = DefaultSettings(EnvConfig(prefix='MYAPP_'))

Profit:

if settings.DEBUG:
    print(settings.SECRET_KEY)
else:
    print(settings.LOCALES)

connect(settings.DB_URL)

Django integration

In your settings.py file:

from coolfig import EnvConfig, load_django_settings

INSTALLED_APPS = (
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',

   'testprj.my_custom_app',
)

MIDDLEWARE_CLASSES = (
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware',
   'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'testprj.urls'

WSGI_APPLICATION = 'testprj.wsgi.application'

TEMPLATES = [
   {
      'BACKEND': 'django.template.backends.django.DjangoTemplates',
      'DIRS': [],
      'APP_DIRS': True,
      'OPTIONS': {
            'context_processors': [
               'django.template.context_processors.debug',
               'django.template.context_processors.request',
               'django.contrib.auth.context_processors.auth',
               'django.contrib.messages.context_processors.messages',
            ],
      },
   },
]

load_django_settings(EnvConfig(), locals())

Then, in each settings submodule of each app, you can define additional setting entries to be added to the main settings object. For example, in testprj/my_custom_app/settings.py you can add the following:

from coolfig import Settings, Value

class AppSettings(Settings):  # The class has to be named AppSettings
   MY_APP_SETTING = Value(str)

Usage is 100% compatible with Django’s settings machinery:

from django.conf import settings

settings.MY_APP_SETTING

History

0.3.0 - 2015-07-20

  • Added first-class support for Django

  • Added some more importing shortcuts (EnvConfig, DictConfig, load_django_settings)

  • Added a DictValue value, able to load multiple keys with the same prefix into the same value

  • Added an API to merge different settings schema into an existing object

0.2.0 - 2015-05-31

  • Added a EnvConfig provider

  • Added a dottedpath value type

0.1.0 – 2015-05-30

  • Initial release

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

coolfig-0.3.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

coolfig-0.3.0-py2-none-any.whl (12.3 kB view details)

Uploaded Python 2

File details

Details for the file coolfig-0.3.0.tar.gz.

File metadata

  • Download URL: coolfig-0.3.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for coolfig-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c3d5702527766a9f5763f88dd497ffe1378aa0aa7c37ce304aa008d4f4ad3014
MD5 e0ef76994de504dbc587307926c19c21
BLAKE2b-256 ba7a9e0149c302e90b5584ba9e1b04afab18d8311f137bd25850e5603a8ba7e5

See more details on using hashes here.

Provenance

File details

Details for the file coolfig-0.3.0-py2-none-any.whl.

File metadata

File hashes

Hashes for coolfig-0.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 e8825fe716feb69af2c84ccd0e030ad09318731fd07d526315fc9321f9cbd935
MD5 6e5ca03adc6fd3685285d3894deb9ac9
BLAKE2b-256 b0a6372e51954dc4608aa768890701ab979ebe250122af8da3be178dfcda91b1

See more details on using hashes here.

Provenance

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