Package: yamlattributes
YamlAttributesYamlAttributes is a utility class to load yaml files and assign the entries to associated class attributes.
This can be used to create a type safe and dynamic configuration class.:floppy_disk: InstallationYamlAttributes can be installed by runningpip install yamlattributes:technologist: UsageThe abstractYamlAttributesclass provides theinitmethod which loads a YAML file and assigns its values to the corresponding class attributes.
A class which inherits fromYamlAttributessimply has to list the desired configuration as class attributes and two additional special attributesyaml_file_pathandyaml_section. After calling theinitmethod the all class attributes wil be assigned the values of the corresponding fields of the YAML file.:monocle_face: APISpecial AttributesAttributeDefaultDescriptionyaml_file_path'./'Sets the path to the YAML file which should be loaded.yaml_section'config'Sets YAML section which contains the desired config fields.init MethodArgsvaluesDescriptionmode'sync','soft_config'Selects the the mode of how the YAML values should update the config class. Thesyncmode keeps the YAML file and the config class in sync. Each attribute in the config class (except of the two special ones and optiona attributes) have to be in the YAML file and vis versa. Thesoft_configmode allows the YAML file to have additional fields which the config class does not have.yaml_file_pathstrInstead of providing the path to the YAML file through the special attribute it can also be passed in the init method. The path passed to the init method overrides the special attributeyaml_sectionstrInstead of providing the YAML section through the special attribute it can also be passed in the init method. The section passed to the init method overrides the special attributeto_dict MethodThe config object can be converted to a dictionary by calling theto_dictmethodOptional AttributesBy default the YAML file has to provide values for all attributes of the config file. By using theOptionaltype hint optional attributes can be added to a config class. For these optional attributes the YAML file is not required to provide values.:rocket: ExampleFirst create your desired config class and set the destination of the YAML file to be loaded through the specialyaml_file_pathattribute.# ./config.pyclassMyConfig(YamlAttributes):yaml_file_path='./configs/my-config.yaml'batch_size:intnum_classes:intoptimizer:strdevice:Optional[str]Make ure the YAML file exists and has all entries the config classMyConfigneeds.# ./configs/my-config.yamlconfig:batch_size:32num_classes:10optimizer:'adam'Finally you can initialize your config class and enjoy accessing config values with autocomplete.# ./main.pyfromconfigimportMyConfigMyConfig.init()# Access config values with autocompleteMyConfig.batch_size:hammer_and_wrench:  ContributingInterested in contributing? Great, thanks for your interest!To fix a bug or add a feature, follow these steps:Forkthe repoCreate a new branch (git checkout -b your-branch)Add your changes and new tests if necessaryMake sure all tests passCommit your changes (git commit -am 'feat: fantastic feature')Push the branch (git push origin improve-feature)Create aPull RequestDevelopingThe required packages to start development can be installed withpipenv install --devThe tests can be run withpipenv run pytestTo build the package runpython3 -m buildYou can then install it locally withpip install .