https://github.com/aphp/confit
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.
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.3%) to scientific vocabulary
Keywords
Repository
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.
Basic Info
- Host: GitHub
- Owner: aphp
- License: bsd-3-clause
- Language: Python
- Default Branch: main
- Homepage: https://aphp.github.io/confit/
- Size: 2.56 MB
Statistics
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 3
- Releases: 23
Topics
Metadata Files
README.md
Confit
Confit is a complete and easy-to-use configuration framework aimed at improving the reproducibility of experiments by relying on the Python typing system, minimal configuration files and command line interfaces.
Getting started
Install the library with pip:
Confit only abstracts the boilerplate code related to configuration and leaves the rest of your code unchanged.
Here is an example:
script.py
```diff + from confit import Cli, Registry, RegistryCollection
- class registry(RegistryCollection):
factory = Registry(("test_cli", "factory"), entry_points=True)@registry.factory.register("submodel") class SubModel:
Type hinting is optional but recommended !
def init(self, value: float, desc: str = ""): self.value = value self.desc = desc
@registry.factory.register("bigmodel") class BigModel: def init(self, date: datetime.date, submodel: SubModel): self.date = date self.submodel = submodel
app = Cli(prettyexceptionsshow_locals=False)
you can use @confit.validate_arguments instead if you don't plan on using the CLI
@app.command(name="script", registry=registry) def func(modelA: BigModel, modelB: BigModel, seed: int = 42): assert modelA.submodel is modelB.submodel print("modelA.date:", modelA.date.strftime("%B %-d, %Y")) print("modelB.date:", modelB.date.strftime("%B %-d, %Y"))
if name == "main":
app()```
Create a new config file
The following also works with YAML files
config.cfg
```ini
CLI sections
[script] modelA = ${modelA} modelB = ${modelB}
CLI common parameters
[modelA] @factory = "bigmodel" date = "2003-02-01"
[modelA.submodel] @factory = "submodel" value = 12
[modelB] date = "2003-04-05" submodel = ${modelA.submodel} ```
and run the following command from the terminal
You can still call the function method from your code, but now also benefit from
argument validation !
```python from script import func, BigModel, SubModel
To seed before creating the models
from confit.utils.random import set_seed
seed = 42 set_seed(seed)
submodel = SubModel(value=12) func( # BigModel will cast date strings as datetime.date objects modelA=BigModel(date="2003-02-01", submodel=submodel), # Since the modelB argument was typed, the dict is cast as a BigModel instance modelB=dict(date="2003-04-05", submodel=submodel), seed=seed, ) ```
modelA.date: February 1, 2003
modelB.date: April 5, 2003
Serialization
You can also serialize registered classes, while keeping references between instances:
```python from confit import Config
submodel = SubModel(value=12) modelA = BigModel(date="2003-02-01", submodel=submodel) modelB = BigModel(date="2003-02-01", submodel=submodel) print(Config({"modelA": modelA, "modelB": modelB}).to_str()) ```
```ini [modelA] @factory = "bigmodel" date = "2003-02-01"
[modelA.submodel] @factory = "submodel" value = 12
[modelB] @factory = "bigmodel" date = "2003-02-01" submodel = ${modelA.submodel} ```
Error handling
You also benefit from informative validation errors:
python
func(
modelA=dict(date="hello", submodel=dict(value=3)),
modelB=dict(date="2010-10-05", submodel=dict(value="hi")),
)
ConfitValidationError: 2 validation errors for __main__.func()
-> modelA.date
invalid date format, got 'hello' (str)
-> modelB.submodel.value
value is not a valid float, got 'hi' (str)
Visit the documentation for more information!
Acknowledgement
We would like to thank Assistance Publique – Hôpitaux de Paris and AP-HP Foundation for funding this project.
Owner
- Name: Greater Paris University Hospitals (AP-HP)
- Login: aphp
- Kind: organization
- Location: Paris
- Website: https://www.aphp.fr/
- Repositories: 35
- Profile: https://github.com/aphp
GitHub Events
Total
- Create event: 23
- Issues event: 3
- Release event: 7
- Watch event: 5
- Delete event: 10
- Issue comment event: 18
- Push event: 91
- Pull request review event: 2
- Pull request event: 29
Last Year
- Create event: 23
- Issues event: 3
- Release event: 7
- Watch event: 5
- Delete event: 10
- Issue comment event: 18
- Push event: 91
- Pull request review event: 2
- Pull request event: 29
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 6
- Total pull requests: 38
- Average time to close issues: 5 months
- Average time to close pull requests: 5 days
- Total issue authors: 3
- Total pull request authors: 3
- Average comments per issue: 0.17
- Average comments per pull request: 0.87
- Merged pull requests: 32
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 24
- Average time to close issues: 5 days
- Average time to close pull requests: 8 days
- Issue authors: 2
- Pull request authors: 3
- Average comments per issue: 0.0
- Average comments per pull request: 0.88
- Merged pull requests: 19
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- percevalw (2)
- aricohen93 (2)
- LucasDedieu (1)
Pull Request Authors
- percevalw (38)
- Thomzoy (6)
- LucasDedieu (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 7,073 last-month
- Total dependent packages: 2
- Total dependent repositories: 2
- Total versions: 24
- Total maintainers: 3
pypi.org: confit
Smart configuration framework
- Documentation: https://confit.readthedocs.io/
- License: Copyright 2023 Assistance Publique - Hôpitaux de Paris Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
Latest release: 0.10.0
published 6 months ago