Metadata-Version: 2.1
Name: comfyconf
Version: 0.0.2
Summary: YAML config parser
License: MIT License
        
        Copyright (c) 2023 Emil Dandanell Agerschou
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/edager/comfyconf
Project-URL: Issues, https://github.com/edager/comfyconf/issues
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyyaml
Requires-Dist: jsonschema
Provides-Extra: dev
Requires-Dist: ruamel.yaml; extra == "dev"
Requires-Dist: yamale; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: coverage; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: isort; extra == "dev"

# comfyconf

## What is it for?

Using YAML configuration files for python require less boilerplate code, and accessing the values by dot notation.

## Installation

```bash
pip install comfyconf
```

## Usage

### Basic

Create a config file in YAML and name it foo.yaml:

```yaml
test:
  title: 'test' 
  ip: '127.0.0.1' 
  port: 5000

production:
  title: 'My amazing server' 
  ip: '1234.255.255.1' 
  port: 1234
```

Now, load it using `make_config`:

```python
>>> from comfyconf import make_config   
>>> config = make_config("foo.yaml")
>>> config.test.ip
'127.0.0.1'
>>> config.production.port
1234  
```

Note that numerical keys are not allowed (even if they're strings in YAML), doing so will raise a `ValueError`.  

### Using ruamel.yaml as parser instead of pyyaml

If you prefer ruamel.yaml or need to parse YAML 1.2 document you can specify `"ruamel"`` as the reader:

```python 
>>> config = make_config("foo.yaml", reader="ruamel")
```

### Validate configuration against a schema 

If you need to be validate that the configuration is compatible with a schema,
you can use validate_config:

First, create a schema:
```json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "$defs": {  
    "connection": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "title": {"type": "string"},
        "ip": {"type": "string", "format":"ipv4"},
        "port": { "type": "integer", "minimum": 1, "maximum": 65535}
      },
      "required": ["title", "ip", "port"]          
    }
  },
  "type": "object",
  "properties": {
    "test": {"$ref": "#/$defs/connection"},
    "production": {"$ref": "#/$defs/connection"}
  }
}
```

```python 
>>> from comfyconf import make_config, validate_config   
>>> config = make_config("foo.yaml", reader="ruamel")
>>> validate_config(config, "schema.json", validator='json')

```
Currently, json-schema (`validator='json'`) is the default but yamale schema can also be used (`validator='yamale'`)  if yamale is installed.

## Contribute

If you find a bug or have a feature request, please raise on issue on [Github](https://github.com/edager/comfyconf/issues). 

Contributions are more than welcome, but please:

 1. Write unittest (pytest) 
 2. Write Numpy styled docstrings     
