{"id":15899959,"url":"https://github.com/jeankossaifi/configmypy","last_synced_at":"2025-09-13T05:30:37.095Z","repository":{"id":61797230,"uuid":"551083586","full_name":"JeanKossaifi/configmypy","owner":"JeanKossaifi","description":"Easy configuration of Python projects.","archived":false,"fork":false,"pushed_at":"2024-05-28T21:25:09.000Z","size":40,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-29T11:32:53.086Z","etag":null,"topics":["argparse","configuration","python","yaml"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/configmypy/","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/JeanKossaifi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-13T20:14:54.000Z","updated_at":"2024-06-06T17:53:45.863Z","dependencies_parsed_at":"2024-06-06T18:09:37.175Z","dependency_job_id":null,"html_url":"https://github.com/JeanKossaifi/configmypy","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"a7baa4a618ec58509ecd7d5ab575161d70be4ff5"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeanKossaifi%2Fconfigmypy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeanKossaifi%2Fconfigmypy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeanKossaifi%2Fconfigmypy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeanKossaifi%2Fconfigmypy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JeanKossaifi","download_url":"https://codeload.github.com/JeanKossaifi/configmypy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232820228,"owners_count":18581279,"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","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":["argparse","configuration","python","yaml"],"created_at":"2024-10-06T10:41:19.772Z","updated_at":"2025-01-07T04:12:53.540Z","avatar_url":"https://github.com/JeanKossaifi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![PyPI](https://img.shields.io/pypi/v/configmypy)\n[![Github Test](https://github.com/JeanKossaifi/configmypy/actions/workflows/test.yml/badge.svg)](https://github.com/JeanKossaifi/configmypy/actions/workflows/test.yml)\n\n# ConfigMyPy\n\nConfigure My Python: Easy configuration of Python projects.\n\n## Quickstart\n\nJust clone the repository and install it, here in editable mode:\n\n```bash\ngit clone https://github.com/JeanKossaifi/configmypy\ncd configmypy\npython -m pip install -e .\n```\n\nThen, assuming you have a configuration file `config.yaml` in your folder, get your configuration using\n```python\nfrom configmypy import ConfigPipeline, YamlConfig, ArgparseConfig\n\npipe = ConfigPipeline([YamlConfig('./config.yaml'),\n                        ArgparseConfig()])\nconfig = pipe.read_conf()\n```\n\nThen just read your parameters from config:\n```\narg = config.arg\narg2 = config['arg2']\n...\n```\n\nThe script will read config.yaml, as well as optional command-line arguments, which will overwrite the config.\n\n## Rationale\n\nHow many times did you start having a large Python project, let's say to run some Machine Learning models, where you wanted to change quickly the parameters.\nThen you want to track them. In you write a small logger. Then you write a small yaml config file to more easily manage the quickly growing list of parameters.\nThen you realize you sometimes need to change some of these parameters on the fly. \nIn comes argparse, and you manually override an increasingly long list of paramters with a code becoming a long list of\n\n```python\nif args.parameter is not None:\n    config['parameter'] = args.parameter\n```\n\n...and there goes your sanity... Along with any hope of properly managing and tracking your experiments. \n\nTo address this frustration, I wrote this minimal package that makes this easy.\n\n## Reading from a `.yaml` config file\n\nImagine you have a `config.yaml` file that looks like this:\n\n```yaml\ndefault:\n  opt:\n    optimizer: 'adam'\n    lr: 0.1\n  data:\n    dataset: 'ns'\n    batch_size: 12\n    \ntest:\n  opt:\n    optimizer: 'SGD'\n```\n\nYou can read that using `configmypy.YamlConfig`: \n\n```yaml\nreader = YamlConfig('./config.yaml', config_name='default')\nconfig, _ = reader.read_conf()\n```\n\n## Bunch configurations\n\nAll our configurations return a Bunch, not a dict. A Bunch is simply a dictionary that exposes its parameters as attributes so you can access them, equivalently, as\n`config['param']` or `config.param`.\n\n## Configuration Pipeline\n\nThe real power of `configmypy` comes from the ConfigPipeline: you can have several steps called sequentially. \nA typical usecase would be: \n1) Read a default (.yaml) config\n2) Optionally overwrite any of those parameters using argparse (command-line arguments)\n3) If the user specified another configuration, update the parameters read so far with that new config\n\nThis would look like this with `configmypy`:\n\n```python\npipe = ConfigPipeline([YamlConfig('./config.yaml', config_name='default'),\n                        ArgparseConfig(config_file=None, config_name=None),\n                        YamlConfig()])\nconfig = pipe.read_conf()\n```\n\nThis will: \n1) first read the `default` section in `config.yaml`\n2) update any parameters with those passed by the user, including additional parameters `config_file` and `config_name` which are automatically passed to the next step\n3) If the user specified a `config_file`, that will be read by the next step and used to update the configuration.\n\nYou can check the configuration by calling `pipe.log()`:\n\n```python\n\u003e\u003e\u003e pipe.log()\n###############################\n#####    CONFIGURATION    #####\n###############################\n\nSteps:\n------\n (1) YamlConfig with config_file=./config.yaml, config_name=default\n (2) ArgparseConfig with additional config={'config_file': None, 'config_name': None}\n (3) YamlConfig with config_file=config.yaml, config_name=test\n\n-------------------------------\n\nConfiguration:\n--------------\n\nopt.optimizer=SGD\nopt.lr=0.1\ndata.dataset=ns\ndata.batch_size=24\n\n###############################\n\n```\n\n## Questions or issues\nThis is very much a project in development that I wrote for myself and decided to open-source so myself and others could easily reuse it for multiple projects, while knowing it is actually tested!\n\nIf you have any questions or find any bugs, please open an issue, or better yet, a pull-request!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeankossaifi%2Fconfigmypy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeankossaifi%2Fconfigmypy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeankossaifi%2Fconfigmypy/lists"}