{"id":37620044,"url":"https://github.com/perslev/yamlhparams","last_synced_at":"2026-01-16T10:37:24.622Z","repository":{"id":57673219,"uuid":"476652624","full_name":"perslev/yamlhparams","owner":"perslev","description":"An extension to the ruamel.yaml YAML parser for roundtrip loading, manipulation and saving of hyperparameters stored in YAML files and basic version control against a separate Python package","archived":false,"fork":false,"pushed_at":"2022-05-04T11:23:59.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-28T19:32:33.104Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/perslev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-01T09:16:46.000Z","updated_at":"2022-04-01T09:20:20.000Z","dependencies_parsed_at":"2022-08-31T08:22:07.125Z","dependency_job_id":null,"html_url":"https://github.com/perslev/yamlhparams","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/perslev/yamlhparams","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perslev%2Fyamlhparams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perslev%2Fyamlhparams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perslev%2Fyamlhparams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perslev%2Fyamlhparams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perslev","download_url":"https://codeload.github.com/perslev/yamlhparams/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perslev%2Fyamlhparams/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-16T10:37:24.551Z","updated_at":"2026-01-16T10:37:24.606Z","avatar_url":"https://github.com/perslev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# YAMLHParams\nA small extension to the `ruamel.yaml` `CommentedMap` YAML parser class (see [https://yaml.readthedocs.io/en/latest/](https://yaml.readthedocs.io/en/latest/)). \nThis extension enables access to and manipulation of hyperparameters stored in YAML files using hierarchical/path-like \n(`/path/to/value`) lookups of attributes and may perform simple version controlling against a separate \nPython package and its parent folder `git` repository. Changes made to the hyperparameters in memory can be easily written to disk preserving comments and \norder of YAML blocks.\n\nThe intended usage is for e.g. machine learning research projects for maintaining a consistent set of hyperparameters \non-disk and in-memory while keeping track of the software version used to run a given set of experiments.\n\n## Installation\n```bash\npip install yamlhparams\n```\n\n## Examples\nGiven a file `hyperparameters.yaml` with content:\n\n```yaml\nfit:\n  n_epochs: 100\n  loss_function:  # Some comment\n    class: cross_entropy\n    kwargs:\n      class_weights: [1.5, 0.4, 2.0]\n  optimizer:\n    learning_rate: 1e-5\n\nlogging:\n  path: /my/path\n  level: WARNING\n```\n\nLoading and accessing hyperparameters using typical dictionary lookup or hierarchical `/path/to/value` styles and \nperforming version control against a 3rd party package `my_ml_package`:\n```python\nfrom yamlhparams import YAMLHParams\nhparams = YAMLHParams('hyperparameters.yaml', \n                      version_control_package_name='my_ml_package')\nprint(hparams['logging']['level'])\n\u003e\u003e WARNING\n\nprint(hparams.get_group('/fit/loss_function/class'))\n\u003e\u003e cross_entropy\n\nprint(hparams.get_group('/fit/optimizer'))\n\u003e\u003e ordereddict([('learning_rate', 1e-05)])\n```\n\nAdding/deleting groups to/from the hyperparameter file:\n```python\nhparams.set_group('/data/splits', {'train_inds':[1, 4, 6], \n                                   'test_inds': [2, 3, 5]}, \n                  missing_parents_ok=True)\n\nhparams.delete_group('/logging')\n\n# Save changes to file, preserving comments and order\nhparams.save_current()\n```\n\nThe modified file now has the following content:\n\n```yaml\n__package_info__:\n  package: my_ml_package\n  version: 0.1.0\n  git:\n    commit: 31dd454\n    branch: main\n\nfit:\n  n_epochs: 100\n  loss_function:  # Some comment\n    class: cross_entropy\n    kwargs:\n      class_weights: [1.5, 0.4, 2.0]\n  optimizer:\n    learning_rate: 1e-5\n\ndata:\n  splits:\n    train_inds:\n    - 1\n    - 4\n    - 6\n    test_inds:\n    - 2\n    - 3\n    - 5\n```\n\nLoading the same hyperparameter file with the installed `my_ml_package` later \nupdated to version `0.2.0` will raise a `RuntimeWarning`:\n\n```\n[...]\nRuntimeWarning: Parameter file indicates that this project was created under \n                my_ml_packagae version 0.1.0, but the current version is 0.2.0. \n                If you wish to continue using this software version on this project dir, \n                manually update to the following lines in the hyperparameter file:\n\n__package_info__:\n  version: 0.2.0\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperslev%2Fyamlhparams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperslev%2Fyamlhparams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperslev%2Fyamlhparams/lists"}