Metadata-Version: 2.1
Name: dataclasses-configobj
Version: 0.0.4
Summary: Easily deserialize Data Classes from ini files
Home-page: https://github.com/JEFuller/dataclasses-configobj
Author: Dave Tapley
Author-email: dave@jefuller.com
License: MIT
Platform: UNKNOWN
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
Description-Content-Type: text/markdown
License-File: LICENSE

# dataclasses-configobj

Hydrate Data Classes from `ini`/`dat`/toml files.

Aims to be [`dataclasses-json`](https://github.com/lidatong/dataclasses-json), but for [`configobj`](https://github.com/DiffSK/configobj).

This is _very alpha_ right now, but the feaures which work, should work:

## Usage

Define the shape of your config:

* Each subsection will be mapped to a nested class
* Each subsection may define a single `_many`
* A `_many` must have type `List[...]`
* The type of `List` of a `_many` shall have a `_name`

Example:

```python
@dataclass
class Single:
    other: str

@dataclass
class OneOfMany:
    _name: str
    val: str

@dataclass
class Config:
    single: Single
    _many: List[OneOfMany]
    optional: Optional[str] = None
```

To load this `.ini` file:

```
[single]
other = hello
[one]
val = apple
[two]
val = banana
```

We can read, validate, and `lift` to an instance of `Config` with:

```pythonfrom dataclasses_configobj import lift, to_specj import to_spec, lift


spec = core.to_spec(Config)
co = configobj.ConfigObj(infile=infile, configspec=spec)

validator = validate.Validator()
co.validate(validator)

config: Config = dataclasses.lift(Config, co)
```

To yield `config`:
```
Config(
    single=Single(other='hello'),
    optional=None,
    withdefault='test123'
    _many=[
        OneOfMany(_name='one', val='apple'),
        OneOfMany(_name='two', val='banana')
    ]
)

