Package: hydralette
HydraletteCreate complex configurations in a simple, pythonic way!DocumentationInstallationpipinstallhydralette# ORpoetryaddhydraletteChangelogv0.2.3change version ofdilldependencyv0.2.2support mixing _fields, _groups and _from_signaturesupport literal values as groupsadd boolean flags as--flagor--no-flagv0.2.1fix yaml representationsupport setting value to None in automatic conversionv0.2.0complete re-design --> breaking changes!easier creation of hierarchical configsv0.1.5Add yaml overridesAdd end-to-end tests with pytestv0.1.4Add documentation athttps://valeknappich.github.io/hydralettev0.1.3Add automatic generation of configs from signatures viafrom_signatureandconfig_from_signaturev0.1.2Add support forconfig groups,references,validationandtype conversionAdd CLI help pagesFeaturesBasicsCreate a config using theConfigclass, passing the config fields as keyword arguments.fromhydraletteimportConfigcfg=Config(a=1,b=2,c="abc")Configobjects can be create from and exported todicts.fromhydraletteimportConfigcfg=Config.from_dict({"a":1,"b":2,"c":"abc"})print(cfg.to_dict())Every hydraletteConfigbe overriden via CLI:fromhydraletteimportConfig,Fieldcfg=Config(a=Field(default=1,help="Lorem ipsum"),b=Config(c=Field(default=2,help="Lorem ipsum")))cfg.apply(["--help"])# or cfg.print_help()# prints:# Usage python script.py [OPTIONS]# --a 1                   Lorem ipsum# --b.c 1                 Lorem ipsumAfter creation, you can override, resolve references, validate and check for missing required arguments.cfg.override(["--a","1"])# overrides defaults to sys.argv[1:]cfg.resolve_references()cfg.validate()cfg.check_required_args()# ORcfg.apply(["--a","1"])# shorthand for the aboveGroupsConfig groups can be very handy to make components interchangeable without requiring them to share a config.fromhydraletteimportConfig,Fieldcfg=Config(model=Config(_groups={"_default":"rnn","rnn":Config(n_layers=2,bidirectional=False),"transformer":Config(n_layers=16,num_attention_heads=8)}))cfg.apply(["--model","transformer"])From signature / existing configOften times, part of your configuration is already implemented somewhere else and duplicating this information creates a source of failure. Instead, you can automatically generate your hydraletteConfigbased on an existing interfacedefcalc(a:int,b=2):passfromhydraletteimportConfig,Fieldcfg=Config(_from_signature=calc)# equivalent tocfg=Config(a=Field(type=int),b=Field(default=2,type=int))FieldsWhen you directly pass a value toConfigs constructor, hydralette will create aFieldunder the hood. To use additional features, you can create it explicitlyconvert: Specify how command-line overrides should be converted to the target type. If not explicitly specified, hydralette tries to use the field'stypeas conversion function (typeis either explicitly specified or automatically derived fromdefault/default_factory).importjsonfromhydraletteimportConfig,Fieldcfg=Config(my_dict=Field(default={"a":1,"b":{"c":2}},convert=json.loads))cfg.apply(['--my_dict',r'{"a": 2, "b": {"c": 3}}'])validate: Constrain what values are valid for your field. If the validity of a value depends on the rest of the config, use_validatein theConfigconstructor instead.fromhydraletteimportConfig,Fieldcfg=Config(n=Field(default=1,validate=lambdan:n>0))cfg.apply(['--n','-1'])# throws: ValidationError: Field validation failed for -1cfg=Config(_validate=lambdacfg:cfg.a>cfg.b,a=1,b=2)cfg.apply()# or cfg.validate()# throws: ValidationError: Config validation failed for {'a': 1, 'b': 2}reference/reference_root: Refer to any other value in the configfromhydraletteimportConfig,FieldfrompathlibimportPathcfg=Config(dir=Path("outputs"),train=Config(checkpoint_dir=Field(reference_root=lambdacfg:cfg.dir/"checkpoints"),# relative to current configmetrics_dir=Field(reference=lambdacfg:cfg.checkpoint_dir.parent/"metrics")# relative to root config))cfg.resolve_references()BacklogCLIgroupsfrom signaturesvalidationconversionreferencesyaml representationpickle serializationallow combining _groups, _fields and _from_signaturespecial support for boolean flags in CLIDev InfoSteps on new release:Run testspytestEdit docsIncrement version inpyproject.tomlAdd changelog toREADME.mdPush increment to GitHubPublish to PyPIpoetry publish --buildPublish docsmkdocs gh-deployCreate release and tag on GitHub