{"id":21702399,"url":"https://github.com/aphp/confit","last_synced_at":"2025-12-12T13:52:58.343Z","repository":{"id":164049464,"uuid":"639464895","full_name":"aphp/confit","owner":"aphp","description":"Confit is a complete and easy-to-use configuration framework aimed at improving the reproducibility of experiments by relying on the Python type annotations, minimal configuration files and a robust CLI.","archived":false,"fork":false,"pushed_at":"2025-08-26T15:29:58.000Z","size":2684,"stargazers_count":11,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-09T09:23:17.117Z","etag":null,"topics":["cli","configuration","interpolation","python","registry","validation"],"latest_commit_sha":null,"homepage":"https://aphp.github.io/confit/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aphp.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"roadmap.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-05-11T13:59:41.000Z","updated_at":"2025-08-26T15:26:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6fe5b09-ae13-45a4-98fb-1397b85ecf9f","html_url":"https://github.com/aphp/confit","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/aphp/confit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aphp%2Fconfit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aphp%2Fconfit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aphp%2Fconfit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aphp%2Fconfit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aphp","download_url":"https://codeload.github.com/aphp/confit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aphp%2Fconfit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276318395,"owners_count":25621649,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-21T02:00:07.055Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cli","configuration","interpolation","python","registry","validation"],"created_at":"2024-11-25T21:15:12.195Z","updated_at":"2025-09-21T22:33:13.084Z","avatar_url":"https://github.com/aphp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Tests](https://img.shields.io/github/actions/workflow/status/aphp/confit/tests.yml?branch=main\u0026label=tests\u0026style=flat-square)\n[![Documentation](https://img.shields.io/github/actions/workflow/status/aphp/confit/documentation.yml?branch=main\u0026label=docs\u0026style=flat-square)](https://aphp.github.io/confit/latest/)\n[![PyPI](https://img.shields.io/pypi/v/confit?color=blue\u0026style=flat-square)](https://pypi.org/project/confit/)\n[![Coverage](https://raw.githubusercontent.com/aphp/confit/coverage/coverage.svg)](https://raw.githubusercontent.com/aphp/confit/coverage/coverage.txt)\n\n\n# Confit\n\nConfit is a complete and easy-to-use configuration framework aimed at improving the reproducibility\nof experiments by relying on the Python typing system, minimal configuration files and\ncommand line interfaces.\n\n## Getting started\n\nInstall the library with pip:\n\n\u003cdiv class=\"termy\"\u003e\n\n```bash\npip install confit\n```\n\n\u003c/div\u003e\n\nConfit only abstracts the boilerplate code related to configuration and\nleaves the rest of your code unchanged.\n\nHere is an example:\n\n\u003ch5 a\u003e\u003cstrong\u003e\u003ccode\u003escript.py\u003c/code\u003e\u003c/strong\u003e\u003c/h5\u003e\n\n```diff\n+ from confit import Cli, Registry, RegistryCollection\n  \n+ class registry(RegistryCollection):\n+     factory = Registry((\"test_cli\", \"factory\"), entry_points=True)\n \n+ @registry.factory.register(\"submodel\")\nclass SubModel:\n    # Type hinting is optional but recommended !\n    def __init__(self, value: float, desc: str = \"\"):\n        self.value = value\n        self.desc = desc\n \n \n+ @registry.factory.register(\"bigmodel\")\nclass BigModel:\n    def __init__(self, date: datetime.date, submodel: SubModel):\n        self.date = date\n        self.submodel = submodel\n \n+ app = Cli(pretty_exceptions_show_locals=False)\n\n# you can use @confit.validate_arguments instead if you don't plan on using the CLI\n+ @app.command(name=\"script\", registry=registry)\ndef func(modelA: BigModel, modelB: BigModel, seed: int = 42):\n    assert modelA.submodel is modelB.submodel\n    print(\"modelA.date:\", modelA.date.strftime(\"%B %-d, %Y\"))\n    print(\"modelB.date:\", modelB.date.strftime(\"%B %-d, %Y\"))\n \n+ if __name__ == \"__main__\":\n+     app()\n```\n\n\nCreate a new config file\n\nThe following also works with YAML files\n\n\u003ch5 a\u003e\u003cstrong\u003e\u003ccode\u003econfig.cfg\u003c/code\u003e\u003c/strong\u003e\u003c/h5\u003e\n\n```ini\n# CLI sections\n[script]\nmodelA = ${modelA}\nmodelB = ${modelB}\n\n# CLI common parameters\n[modelA]\n@factory = \"bigmodel\"\ndate = \"2003-02-01\"\n\n[modelA.submodel]\n@factory = \"submodel\"\nvalue = 12\n\n[modelB]\ndate = \"2003-04-05\"\nsubmodel = ${modelA.submodel}\n```\n\nand run the following command from the terminal\n\n\u003cdiv class=\"termy\"\u003e\n\n```bash\npython script.py --config config.cfg --seed 43\n```\n\n\u003c/div\u003e\n\nYou can still call the `function` method from your code, but now also benefit from\nargument validation !\n\n```python\nfrom script import func, BigModel, SubModel\n\n# To seed before creating the models\nfrom confit.utils.random import set_seed\n\nseed = 42\nset_seed(seed)\n\nsubmodel = SubModel(value=12)\nfunc(\n    # BigModel will cast date strings as datetime.date objects\n    modelA=BigModel(date=\"2003-02-01\", submodel=submodel),\n    # Since the modelB argument was typed, the dict is cast as a BigModel instance\n    modelB=dict(date=\"2003-04-05\", submodel=submodel),\n    seed=seed,\n)\n```\n\n```\nmodelA.date: February 1, 2003\nmodelB.date: April 5, 2003\n```\n\n#### Serialization\n\nYou can also serialize registered classes, while keeping references between instances:\n\n```python\nfrom confit import Config\n\nsubmodel = SubModel(value=12)\nmodelA = BigModel(date=\"2003-02-01\", submodel=submodel)\nmodelB = BigModel(date=\"2003-02-01\", submodel=submodel)\nprint(Config({\"modelA\": modelA, \"modelB\": modelB}).to_str())\n```\n\n```ini\n[modelA]\n@factory = \"bigmodel\"\ndate = \"2003-02-01\"\n\n[modelA.submodel]\n@factory = \"submodel\"\nvalue = 12\n\n[modelB]\n@factory = \"bigmodel\"\ndate = \"2003-02-01\"\nsubmodel = ${modelA.submodel}\n```\n\n#### Error handling\n\nYou also benefit from informative validation errors:\n\n```python\nfunc(\n    modelA=dict(date=\"hello\", submodel=dict(value=3)),\n    modelB=dict(date=\"2010-10-05\", submodel=dict(value=\"hi\")),\n)\n```\n\n```\nConfitValidationError: 2 validation errors for __main__.func()\n-\u003e modelA.date\n   invalid date format, got 'hello' (str)\n-\u003e modelB.submodel.value\n   value is not a valid float, got 'hi' (str)\n```\n\n\n\n\nVisit the [documentation](https://aphp.github.io/confit/) for more information!\n\n## Acknowledgement\n\nWe would like to thank [Assistance Publique – Hôpitaux de Paris](https://www.aphp.fr/)\nand [AP-HP Foundation](https://fondationrechercheaphp.fr/) for funding this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faphp%2Fconfit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faphp%2Fconfit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faphp%2Fconfit/lists"}