Python package that allows to parse typed JSON configs defined by python dataclasses
Project description
PythonConfigParser
easy, light-weight fully-typed python configs. not more, not less.
Usage
define your config stucture in a dataclass like
from dataclasses import dataclass
from typing import List
@dataclass
class DummyConfigElement:
name: str
list: List[int]
another_list: List[float]
from file
First initialize the config parser with the path to the module with the config definitions.
parser = JSONConfigParser(datastructure_module_name="mysrc.datastructures.configs")
# Then parse the config from file.
my_config = parser.parse_from_file("myconfig.json")
from dictionary
my_config_dict = {"type_name" : "mysrc.datastructures.configs.a"}
my_config = JSONConfigParser().parse(my_config_dict)
type definition
There are two ways to define the configs type:
- specified in the config itself
- e.g in the code example above
- path to the config class must be specified as str in the config as key "type_name"
- specified when parsing the config
- if the config has no key "typed_config" set, the type can be specified when parsing the config
from mysrc.datastructures.configs import a
my_config_dict = {"some_key" : "some_value"}
my_config = JSONConfigParser().parse_typed(my_config_dict,a)
Features
- fully typed json configs
- nested configs
- dict object into typed dataclass
Installation
pip install cfgparser
Coming Features
- yaml support
- typed optional support
- typed union support
- specify config from cli
- cd pipeline
- post hock
- distributed configs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cfgparser-1.0.4.tar.gz
(8.2 kB
view hashes)
Built Distribution
Close
Hashes for cfgparser-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71494e307aadc98420bc324ff68c2b17616f22489bb10299e238d22c4b6c6517 |
|
MD5 | c052b18db89cb2b23e790c51c0bc6c9b |
|
BLAKE2b-256 | 6a9ce1ea35cfef1870535b84c722c7d02ce1c0281c4759a97760fd3d9fb29b15 |