COOLFIG
Coolfig is a library to easily write configuration specifications to be fulfilled by various sources.
Free software: MIT license
Documentation: http://coolfig.rtfd.org
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
3.1.0 - 2018-08-23
Make EnvDirConfig importable from coolfig.
3.0.0 - 2018-08-23
Removed explicit support for secrets in favor of EnvDirConfig and a FallbackProvider.
Use black and isort for formatting.
Improved tests coverage
2.0.0 - 2018-08-03
Support for Docker secrets.
1.0.2 - 2016-03-14
Additional bug-fixing.
1.0.1 - 2016-03-14
Fixed a bug in AppConfig checking.
1.0.0 - 2016-03-14
Added support for Django AppConfig (including custom settings path configured with a settings property on the config class.
Officially supporting Django 1.4, 1.5, 1.6, 1.7, 1.8 and 1.9, running on Python 2.7, 3.4 (where Django supports itself supports it) and PyPy.
0.4.0 - 2015-10-05
Added support for the CACHES Django settings directive
Added support for computed_values
Added initial documentation stub
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
Metadata
Release files for coolfig 3.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| coolfig-3.1.0.tar.gz | 12.8 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| coolfig-3.1.0-py3-none-any.whl | Python 3 | none | any | Details |
| coolfig-3.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 43.6 kB
Release files / coolfig-3.1.0.tar.gz
| Download URL | coolfig-3.1.0.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0fb5d6988f6afa0019dc14c9872ecc4563787d4e0f0e81160b5da9b057804b6d
|
|
BLAKE2b-256 checksum How to use checksums |
a69e79928f308bf8e147bb4fa93a2ee057b112c02a8b78ac6f5e0d2ac2af2ade
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.6
|
Release files / coolfig-3.1.0-py3-none-any.whl
| Download URL | coolfig-3.1.0-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
036e9be6aac073eccffa69e15743a5937abe20feb4f32bb7b41a7ed3a281bcab
|
|
BLAKE2b-256 checksum How to use checksums |
7011ecab31792f6e04290e4992f4d995a29eee81c0dfd92d61c04fcb8658371a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.6
|
Release files / coolfig-3.1.0-py2.py3-none-any.whl
| Download URL | coolfig-3.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
9cbf1e08c82f45055aa77d381ca4adc8ac80123b3cefe5869f09efbf5f34ffeb
|
|
BLAKE2b-256 checksum How to use checksums |
7499b80db7a8819c799881896d4b3e514ac90dc39ccc5ed4e9a4aecd9b017de3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.6
|