Application configuration via Python logging.config
Project description
Clor
Clor is a tiny wrapper around logging configuration system [1], which allows its reuse for general application configuration. The name was coined this way: “configurator” → “c10r” → “clor”.
Usage
Normally there’s a configuration module (e.g. envconf.py), or a YAML file. Here is a CherryPy example:
base = {
'global' : {
'server.socket_host' : '127.0.0.1',
'server.socket_port' : 8080,
'server.thread_pool' : 8
},
'app' : {
'api' : {
'/' : {
'request.dispatch' : {
'()' : 'cherrypy._cpdispatch.MethodDispatcher'
}
}
}
}
}
production = (base, {
'global' : {
'server.socket_host' : '0.0.0.0',
'server.thread_pool' : 16,
'tools.auth_basic.on' : True,
'tools.auth_basic.realm' : 'App',
'tools.auth_basic.checkpassword' : 'ext://someapp.password.checker'
},
})
development = (base, {
'global' : {
'server.thread_pool' : None,
},
'app' : {
'api' : {
'/' : {
'tools.response_headers.on' : True,
'tools.response_headers.headers' : [('Access-Control-Allow-Origin', '*')]
}
},
'api2' : 'cfg://app.api'
}
})
A few observations:
Nest dictionaries are merged recursively
logging’s ext pseudo-protocols
logging’s cfg pseudo-protocols
logging’s instantiation with () key
Keys having None value are removed
Then in your bootstrapping code you can do:
import clor
from . import envconf
config = clor.configure(*getattr(envconf, 'production'))
cherrypy.config.update(config)
cherrypy.tree.mount(ApiApplication(), '/api', config['app']['api'])
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
Clor-0.4.0.tar.gz
(4.8 kB
view details)
File details
Details for the file Clor-0.4.0.tar.gz.
File metadata
- Download URL: Clor-0.4.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a74af86685e05f8db4230f4ae0703a5604b602133edcc027a4a7d62a672b49d2
|
|
| MD5 |
1748aa079026626f85edc54135ecf71d
|
|
| BLAKE2b-256 |
f702d9c4e744d7bfe331b7b76ca455753330618ff4ae1670a408a2df8e99480e
|