Tree Struct Config - A Tree Struct Configuration module for python, support dump from/to JSON
Project description
A Tree Struct Configuration module for python, support dump from/to JSON/TOML(todo).
Install
pip install TreeStructConfig
Usage
from tree_view_config import RootNode, BranchNode, StringLeaf, IntLeaf, BooleanLeaf
class Config(RootNode):
username = StringLeaf('admin')
password = StringLeaf('password')
class Auth(BranchNode):
username = StringLeaf('admin')
password = StringLeaf('password')
class Wireless(BranchNode):
class AP(BranchNode):
enabled = BooleanLeaf(True)
interface = StringLeaf('uap0') # DON'T CHANGE IT
ssid = StringLeaf('PiRouter')
password = StringLeaf('password')
hw_mode = StringLeaf('n')
channel = IntLeaf(1)
class Client(BranchNode):
enabled = BooleanLeaf(False)
ssid = StringLeaf('ssid')
password = StringLeaf('password')
data = '''
{
"Auth": {
"password": "xxxxxxxx",
"username": "admin"
},
"Wireless": {
"AP": {
"channel": 1,
"enabled": true,
"hw_mode": "n",
"interface": "uap0",
"password": "xxxxxxxx",
"ssid": "PiRouter"
},
"Client": {
"enabled": false,
"password": "xxxxxxxx",
"ssid": "ssid"
}
}
}
'''
config = Config()
print(config.dumps())
print('--------')
config.loads(data)
print(config.Wireless.AP.password)
{
"Auth": {
"password": "password",
"username": "admin"
},
"Wireless": {
"AP": {
"channel": 1,
"enabled": true,
"hw_mode": "n",
"interface": "uap0",
"password": "password",
"ssid": "PiRouter"
},
"Client": {
"enabled": false,
"password": "password",
"ssid": "ssid"
}
},
"password": "password",
"username": "admin"
}
--------
xxxxxxxx
Alternative
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
TreeStructConfig-0.1.0.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for TreeStructConfig-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3e8eabc6925a98cd010a3cee7c92f2ae81738f64b4ca8dd79fbf8bcc1599762 |
|
MD5 | 92e569e900884f794705dd02b74c1919 |
|
BLAKE2b-256 | 0095ed949fc8520f2c5c08f032f201616d28f8bfef24e9b5e106e62272536036 |