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
_manymust have typeList[...] - The type of
Listof a_manyshall 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dataclasses-configobj-0.0.4.tar.gz.
File metadata
- Download URL: dataclasses-configobj-0.0.4.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96e77cf0e2a38d66b3859e36b8224ef157452a9e14ba5091e727b0df327c3be6
|
|
| MD5 |
a85c6c2fe4e253659df4308f2805069f
|
|
| BLAKE2b-256 |
0302dced431be7626508c0244998b3f606e6df0cac27022a47ed9e6b7e58ab16
|
File details
Details for the file dataclasses_configobj-0.0.4-py3-none-any.whl.
File metadata
- Download URL: dataclasses_configobj-0.0.4-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63c0372017ed80117e283ae083d65fe77258063d08100631060bb60d409de8cc
|
|
| MD5 |
e993dfa467e52f7f2e5df61575f5f415
|
|
| BLAKE2b-256 |
9f25f8d134f9206c552c5daa7539f4c51a25bee45297a859ec0716ecd049d5b9
|