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,
_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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e67eecd3a5bc4064b39027c04d6cc9ce82c35e88695ea07744e4c08109c4de08 |
|
MD5 | 4c501ff6827f9db7a385de990d2d2af0 |
|
BLAKE2b-256 | 562fd347c2adbcf08183b85e767778563465de2e43e52a0eaecf16a5af8e6078 |
Close
Hashes for dataclasses_configobj-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0544ce3ebe75738238c991089c9b80b2d9a98878888b65621e524d3b8d2ceac2 |
|
MD5 | e026d4e50558cc82d35933b32670f0a0 |
|
BLAKE2b-256 | e30edde5907577e6218f2ce22c96d52b51d869c815ce5f55e14577afcad58ff4 |