Easily deserialize Data Classes from ini files
Project description
dataclasses-configobj
Hydrate Data Classes from ini
/dat
/toml files.
Aims to be dataclasses-json
, but for 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 typeList[...]
- The type of
List
of a_many
shall have a_name
Example:
@dataclass
class Single:
other: str
@dataclass
class OneOfMany:
_name: str
val: str
@dataclass
class Config:
single: Single
_many: List[OneOfMany]
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:
from dataclasses_configobj import to_spec, lift
spec = core.to_spec(Config)
configobj = configobj.ConfigObj(infile=infile, configspec=spec)
validator = validate.Validator()
configobj.validate(validator)
config: Config = core.lift(Config, root)
To yield config
:
Config(
single=Single(other='hello'),
_many=[
OneOfMany(_name='one', val='apple'),
OneOfMany(_name='two', val='banana')
]
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for dataclasses-configobj-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fa175a02d61f892f57e6414297935b6d5096800209f7b4060c1653e79bc1dd1 |
|
MD5 | 03ed1c6f91b00789a420fa0972dff5ec |
|
BLAKE2b-256 | 1d65a9edc224ec16dab3b9636d1bc330019f1220b7664586dbb42f89e985af3a |
Close
Hashes for dataclasses_configobj-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d53b33ec745d5738cec7f5a5612d6f16004e16e496d443ff9791fbd1fba37a4 |
|
MD5 | de404d81f708865bf4c37daea59d90f7 |
|
BLAKE2b-256 | b23693482313ba95ed07ee4ecffb0bfc490caeaefab09d6865a24584daccf258 |