An easy way to provide environ backed config in your projects.
Project description
A simpler, clearer approach to configuration.
Quick Start
from confucius import BaseConfig
class Config(BaseConfig)
HOST = '127.0.0.1'
PORT : int = 8000
DEBUG : bool = False
from myapp import Server
from config import Config
server = Server(Config.HOST, Config.PORT)
$ python app.py
- Starting server: 127.0.0.1:8000
$ PORT=80 python app.py
- Starting server: 127.0.0.1:80
$ DEBUG=y python app.py
- Starting debug server: 127.0.0.1:80
Types
Any ANGRY_SNAKE_CASE attributes of a BaseConfig sub-class will be intercepted by the meta-class, and checked for in the environment using os.getenv.
Their type will be determined by their annotation in the class, or fall back to str.
Methods will automatically behave like property`s, with access to `self.
Handling of type casting can be overridden [as it is for bool] by adding it to the __types__ dict:
class Config(BaseConfig):
__types__ = {
json: lambda v: json.loads(v) if isinstance(v, str) else v,
}
LOGGING : json = {'version': 1 ...}
All types defined on parent Config classes will be merged with this dict.
Inheritance
Classes, as usual, inherit from their parents. If the type of an attribute is changed, it will raise an AssertionError.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.