Package: easy-flags
The goal of this nano-project is to provide simple alternative forargparseby adding some new features:easy definitiontype checking (with static type checking tools)reusabilityInstallationpipinstalleasy_flagsBasic examplefoo.pyfromeasy_flagsimportSimpleConfigclassMyConfig(SimpleConfig):int_val=4bool_val=Truewith_doc=0.4,'some docs'# type: floatwithout_default=None,int,'another docs'# type: boolif__name__=='__main__':# command line arguments will be parsed after ::define callc=MyConfig().define().print()print('bool_val:',c.bool_val)Run:$ python foo.py

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|  bool_val        : True
|  int_val         : 4
|  with_doc        : 0.4
|  without_default : None
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool_val: True

Process finished with exit code 0


$ python foo.py -h

usage: foo.py [-h] [--bool_val | --no-bool_val] [--int_val INT_VAL]
                     [--with_doc WITH_DOC] [--without_default WITHOUT_DEFAULT]

optional arguments:
  -h, --help            show this help message and exit
  --bool_val            bool, default: True
  --no-bool_val
  --int_val INT_VAL     int, default: 4
  --with_doc WITH_DOC   float, default: 0.4 - some docs
  --without_default WITHOUT_DEFAULT
                        int, default: None - another docsAlternative definitionfromeasy_flagsimportConfig,IntField,BoolField,FloatFieldclassMyConfig(Config):int_val=IntField(4)bool_val=BoolField(default=True)with_doc=FloatField(0.4,'some docs')without_default=IntField(doc='another docs')Reusabillityfromeasy_flagsimportConfigclassModelConfig(Config):layers=4time_steps=256cell_size=256dropout=1.0# same as model config + additional parametersclassTrainingConfig(ModelConfig):lr=0.001epochs=10000dropout=0.9# change parent argDocstringsIf you want to add help message for field (which will be displayed if you run script with--helpflag), then you need to add it  after flags’ default value:classExampleConfig(BaseConfig):foo=5.0,'Some float field.'bar='field with only default docstring'./script.py--helpusage:test_base.py[-h][--barBAR][--fooFOO]optionalarguments:-h,--helpshowthishelpmessageandexit--barBARStringfield,default='field with default docstring'.--fooFOOFloatfield,default=5.0.Somefloatfield.BooleansBoolean flag with spefied in config name will set destination value toTrue, and the same flag prefixed with ‘no-’ will set value toFalseclassExampleConfig(BaseConfig):cache=Truef=False./script--cache-f# cache=True, f=True./script--no-cache--no-f# cache=False, f=FalseShort flag namesIf flag name consists only from one letter then it can be specified with one dash instead of two.classExampleConfig(BaseConfig):e=100,'number of epochs'b=True./train.py-e42-b# also valid with two dashes./train.py--e42--b./train.py--e42--no-bSpecify type for tuplesclassExampleConfig(BaseConfig):lr=0.001,'learning rate'conf=ExampleConfig()conf.define()In example above pre-definedconf.lris obviously not a float and some static checkers after typec hecking will make a warning that they expected a float as argument for some function but got tuple instead. Fortunately we can help IDE by adding special comment with proper after-define type:classExampleConfig(BaseConfig):lr=0.001,'learning rate'# type: float