Package: upsilonconf
UpsilonConfUpsilonConf is a simple configuration library written in Python.A few features that you might find interesting/useful:dict-like configuration object with attribute access (cf.attrdict)hierarchical indexing by means of tuples ordot-strings(cf.omegaconf)read from/write to various file formatsuse hierarchical configs with options (cf. config groups inhydra)retrieve and manipulate config using CLI (cf.omegaconf)minimal dependencies (cf.attrdict)configs with overwriting protection to prevent unexplainable bugsHow to installUsingpipto install from PyPI:python-mpipinstallupsilonconfOptional dependencies (e.g.pyyaml) can be included usingpython-mpipinstallupsilonconf[YAML]Usingcondato install from Anaconda:condainstallhoedt::upsilonconfOptional dependencies (e.g.pyyaml) have to be installed separately.How to Use>>>importupsilonconf>>>fromupsilonconfimportPlainConfigurationasConfigurationCreationload config from file>>>conf=upsilonconf.load("my_config.yml")or directly create config object>>>conf=Configuration(key1="value1",sub={"key1":1,"key2":2})IndexingAccess values the way you like>>>assertconf["key1"]==conf.key1>>>assertconf.sub.key2==conf["sub","key2"]>>>assertconf["sub","key1"]==conf["sub.key1"]>>>assertconf["sub.key2"]==conf.sub.key2Cool Tricksunpack configurations to function arguments>>>deftest(key1,key2):...returnkey1+key2>>>test(**conf.sub)3convert config to flatdict>>>conf.to_dict(flat=True){'key1':'value1','sub.key1':1,'sub.key2':2}merge configurations with|>>>merged=conf|{"sub.key2":3,"sub.key3":2}>>>merged.sub.key23>>>merged.sub.key32More details can be found in thedocumentationflexible I/Osupport for different file formats>>>conf=upsilonconf.load("config.yaml")# with patched float parsing>>>upsilonconf.save(conf,"config.json")# with indentation by defaulttransform non-identifier keys in files on-the-fly>>>conf=upsilonconf.load("config.yaml",key_mods={" ":"_"})>>>upsilonconf.save(conf,"config.json",key_mods={"_":" "})organise hierarchical configs in directories>>>upsilonconf.save({"key":"option1"},"config_dir/config.json")>>>upsilonconf.save({"foo":1,"bar":2},"config_dir/key/option1.json")>>>upsilonconf.save({"foo":2,"baz":3},"config_dir/key/option2.json")load arbitrary parts of hierarchy>>>conf=upsilonconf.load("config_dir/key")>>>conf==Configuration(...option1={"foo":1,"bar":2},...option2={"foo":2,"baz":3}...)hierarchies enable option feature>>>conf=upsilonconf.load("config_dir")>>>conf==Configuration(key={"foo":1,"bar":2})store hierarchy to directory with a default file format>>>upsilonconf.save(conf,"backup")CLI helperread command-line arguments>>>conf=upsilonconf.from_cli()parse arbitrary arguments to construct config>>>conf=upsilonconf.from_cli(["key=1","sub.test=2"])>>>assertconf==Configuration(key=1,sub={"test":2})use file as base config>>>conf=upsilonconf.from_cli(["--config","config.yaml","key=1","sub.test=2"])>>>result=upsilonconf.load("config.yaml")>>>result.overwrite_all(key=1,sub={"test":2})>>>assertconf==resultenhance existing argparser>>>fromargparseimportArgumentParser>>>parser=ArgumentParser()>>># add other arguments...>>>conf,args=upsilonconf.from_cli(parser=parser)FeedbackThis library is very much a work in progress.
I welcome any feedback, especially in shaping the interface.
Of course, also bug reports and feature requests are very useful feedback.
Just create anissueon github.