Json config files with a statically defined structure.
Project description
staticconfig
Json config files with a staticly defined structure.
This is common code which I used accross many projects.
Usage
A config file's structure is defined by subclassing Config
and filling the constructor with attribute assignments.
Then a file is loaded with the from_json
classmethod:
- If the file exists, it returns an instance of the config class.
- If the file does not exist, it creates one and raises a ConfigError.
The class Namespace
provides syntactic sugar around dicts.
Example
from staticconfig import Namespace, Config
class MyConfig(Config):
def __init__(self):
super().__init__()
self.option1 = "default1"
self.option2 = 0
self.option3 = Namespace()
self.option3.suboption1 = True
self.option3.suboption2 = ["en", "de"]
# If the file doesn't exists this will create it with the default values and raise a ConfigError
config = MyConfig.from_json("config.json")
The produced config file:
{
"option1": "default1",
"option2": 0,
"option3": {
"suboption1": true,
"suboption2": [
"en",
"de"
]
}
}
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
staticconfig-0.0.1.tar.gz
(2.9 kB
view hashes)
Built Distribution
Close
Hashes for staticconfig-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a09004cc44407cd2e4dcdc7c9256e20b752d3599da8d6d23d0fdc246a226919 |
|
MD5 | 09b722b515936fe581dc0a5e9f059b0a |
|
BLAKE2b-256 | bbc385daa81de3b9c93cb5a15895bd1a89158a0ef24bb4ad20fc030dc2985a1a |