Package: easyconf
EasyConfEasy file-based and environment configuration.UsageFirst create aConfigobject:config=easyconf.Config('config.yaml')Then reference a configuration variable as an attribute of this object:some_variable=config.SOME_VARIABLE()At runtime, EasyConf will try to each variable from the following sources
in order:A matching environment variableA matching variable within the configuration fileThedefaultattribute (if no attribute is provided, aneasyconf.config.RequiredConfigVarMissingexception will be raised)Config file generationIf theConfigfile doesn’t exist yet and the file location is writable,
EasyConf will generate it using theinitialvalues and commenteddefaultvalues defined in each configuration variable.If the configuration file is within a git repository it will also be added to
the.gitignorefile.Don’t hide configuration variables within conditional statements, load them at
the top of a module so they can be generated regardless.If you don’t want file generation for non-existant configuration, usegenerate=Falsewhen instantiating theConfigobject.Example Django configurationimporteasyconfconfig=easyconf.Config('myproject.yaml')DEBUG=config.DEBUG(default=False)DATABASES={'default':config.DATABASE(default='postgres:///myproject',cast=easyconf.dict_or_url,)}SECRET_KEY=config.SECRET_KEY(initial=easyconf.random_text_generator(60))Configuration Variable optionsdefaultThe default value for the variable if it is not provided in the environment
or in the configuration file.initialA value or callable used to set the initial value of a variable in the
configuration file.helpHelp text to use in the configuration file for this variable.castA callable to convert an incoming value (from the environment or default
value) to the correct Python type.Set thecast_from_configattribute of this callable toTrueif it
is safe to cast from the configuration file as well.ConfigObject optionsdefault_filesA file or list of files to attempt to read configuration variables from. If
multiple files are provided, only the first one found will be used.If none of the provided files are found, the first one in a writable
location will be created and populated automatically.file_env_varAn environment variable which could be used to specify the configuration
file path.If provided and an environment variable matches, this overrides anydefault_filesspecified.generateWhether to generate a new config file if none of the default_files can be
loaded. Defaults toTrue.Helper Moduleseasyconf.dict_or_urlExpand url strings defined indjango-environinto dictionaries. For example:>>>importeasyconf>>>easyconf.dict_or_url('mysql:///abc'){'NAME': 'abc', 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', 'ENGINE': 'django.db.backends.mysql'}This will also cast url strings coming from the configuration file.easyconf.random_text_generatorCreates a function that can be called to securely generate a random text string
of a predefined length (containing base64 characters).Useful for theinitialconfiguration variable option.>>>importeasyconf>>>gen=easyconf.random_text_generator(20)>>>gen()'sYw0D/7xjXqxfCyUdHqr'>>>gen()'ig1Z1n+mFLt+qYNOmD6I'Change Log1.3.1 (2019-08-26)Don’t require git executable to be installed.1.3 (2019-08-02)Use environment values for automatic configuration generation.1.2.2 (2019-08-02)Correctly lock downruamel.yamlthis time (it’s v0.16, not v16).1.2.1 (2019-08-01)Avoid new version ofruamel.yamlwhich changed loading format.1.2 (2019-05-21)When generating a config that is within a git repository, add it to.gitignore.If a cast callable has acast_from_configattribute set toTrue, cast
values coming from the configuration file. This is set toTruefor thedict_or_urlhelper method.1.1.1 (2019-05-16)Fix issue with generating multiple comments (for multiple default values) at
the end of the YAML config.Cast default values when writing to config.1.1 (2019-05-15)Allow explicit disabling of automatic config generation.Cast default values if acastargument is provided.1.0 (2019-05-15)Initial Release