Package: pyflexconfig
pyflexconfigYou prefer using direct Python files to provide configuration data to your Python application,
just because you can provide any object type you'd prefer in your configuration file.You want to place your custom configuration file anywhere you'd prefer, in traditional places like/etcor wherever you prefer.You want your app to provide some default values to some or all configuration data.But you may prefer something else than Python files (YAML, JSON, XML, etc.), just provide your own
parser.pyflexconfigis just another kid in the block in the settings / options / configuration data
management game that fulfills these requirements.FeaturesProvide the default configuration programmatically, with a default file in your package or through
environment variables.Override the default configuration options with a custom configuration file. You can override one,
two or all default configuration options.You don't like Python configuration files for onr reason or another, even when executed in a
sandbox. Okay, provide your own parser.The configuration container is just a global object on which you can add attributes. I recommend
using atypes.SimpleNamespaceobject but anything may do the job.You may provide the custom configuration file either through conventional places
(ie./etc/my_custom_config.py), explicitly through a dedicated command line option, or through an
environment variable.The default filter keeps only UPPERCASED options not starting with an underscore. This allows to
use temporary variables with lowercase names in your configuration files, that are not exposed in
the resulting configuration object. You may provide your own filter if you want other rules or add
other rules to the default one.You may finally provide a validator if you need to check the type / value of some or all
configuration options.InstallationUsing pyflexconfigpyflexconfigrequires Python 3.6 or later. Install it with the usual pip dance :pip install pyflexconfigNote thatpyflexconfigruns on any operating system and does not require packages outside the
stdlib.Develop on a fork of pyflexconfigOf course, provide and activate a dedicated virtual environment with python 3.6 or later, forkpyflexconfig, then:git clone <your fork URL>cd pyflexconfigpip install -e .[dev]Please work from thedevelopbranch that supposed to include the latest validated developments.Please rebase your fork on thedevelopbranch and fix the unit tests (runpytest) before issuing
a pull / merge request on thedevelopbranch of the original Git repository.Ah ! And of course file an issue that explains your changes.Using pyflexconfigA basic usage :Your default config filedefaultsettings.py:# Warning: do not import here somethong that's not in the stdlibONE=1TWO=2# ...Thesettings.pymodule in the same directory:importpathlibfromtypesimportSimpleNamespacefrompyflexconfigimportbootstrapconfig=SimpleNamespace(# "hardcoded" default optionsTHREE=3,# ...)# Load the default config that ships in the package_default_config_path=pathlib.Path(__file__).resolve().parent/"defaultsettings.py"bootstrap(config,default_path=_default_config_path)And your main application:from.settingsimportconfigdefmain():print(config.ONE)print(config.TWO)print(config.THREE)if__name__=="__main__":main()For more examples, please browse thedemo/directory of the repository
as well as thetests.pymodule.View the full API issuing in the console:python -c "import pyflexconfig; help(pyflexconfig)"LicenseThis software is provided under the terms of the MIT license. See theLICENSEfile in the Git
repository orhere.AuthorThis software comes fromGilles Lenfant's damaged brain.The development ofpyflexconfigis sponsored by theCaisse des
Depots.LinksGithubIssues trackerHistory1.0.2 - 2020/7/5Bugfix: Accepting pathlib.Path objects as well as str paths.1.0.1 - 2020/6/19Removedpython-dotenvfrom requirements (not used)Some typos in README.mdHistory file1.0.0 - 2020/6/18initial release