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]
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:
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')
]
)
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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96e77cf0e2a38d66b3859e36b8224ef157452a9e14ba5091e727b0df327c3be6 |
|
MD5 | a85c6c2fe4e253659df4308f2805069f |
|
BLAKE2b-256 | 0302dced431be7626508c0244998b3f606e6df0cac27022a47ed9e6b7e58ab16 |
Close
Hashes for dataclasses_configobj-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63c0372017ed80117e283ae083d65fe77258063d08100631060bb60d409de8cc |
|
MD5 | e993dfa467e52f7f2e5df61575f5f415 |
|
BLAKE2b-256 | 9f25f8d134f9206c552c5daa7539f4c51a25bee45297a859ec0716ecd049d5b9 |