Easily serialize Data Classes to and 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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a9f20e65ab2df21df90c5d586b0d58ba8b0635c5cc5727864de3faac79c4380 |
|
MD5 | 6a8267c9524230fa40f5358746b79aa7 |
|
BLAKE2b-256 | 3a29a6c7c7e4669235bd6c4c5a244d5957c7ebe786c89f76d5792057c67fa3d2 |
Close
Hashes for dataclasses_configobj-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e530bf3b3ed000d6b525ad2d8f5150c789964001dc524c7bcc3093bc4c4f1828 |
|
MD5 | b057e67ccffb3f7563af60df6841603f |
|
BLAKE2b-256 | beaa8227d27a7a3d66b4c953d4c7caa425a356545db581d41e58f41d1fe8a8d7 |