Reads and write json files as a configuration file, supports nested json values.
Project description
yet-another-json-config
Python class to reads and write json files as a configuration file, supports nested json values.
Examples
Initializing Config
from yet_another_json_config import Config
c = Config('./tests/test.json')
Listing Settings
from yet_another_json_config import Config
c = Config('./tests/test.json')
print(c.settings)
Output
{
"test": "test",
"varUserTest": "test_$user$",
"nestedTest": {
"test": "test"
},
"nestedTest2": {
"nested": {
"test": "test"
}
},
"get": "test"
}
Get Setting
Settings can be obtained two ways through the method get
Class Method get
# setting a basic setting
c.get('test')
# setting a nested setting via list of strings
c.get('nestedTest2', 'nested', 'test')
# setting a nested setting via tuple
c.get(('nestedTest2', 'nested', 'test'))
key
Method
# setting a basic setting
print(c['test'])
# setting a nested setting
print(c['nestedTest2']['nested']['test'])
Set Setting
Settings can be both created and modified using the same methods. If a setting does not exist and one of the following methods is used, it will be created. If the setting already exists, it will be updated.
Class Method set
This method supports *args for defining the keys for a setting. This means that a list of strings (not type of list) or a tuple can be passed to set the value.
# setting a basic setting
c.set('test', value='test2')
# setting a nested setting via list of strings
c.set('nestedTest2', 'nested', 'test', value='test2')
# setting a nested setting via tuple
c.set(('nestedTest2', 'nested', 'test'), value='test2')
key
Method
# setting a basic setting
c['test'] = 'test2'
# setting a nested setting
c['nestedTest2']['nested']['test'] = 'test2'
Delete Setting
Settings can be deleted two ways through the method delete
and the del
statement. As well, nested settings can also be deleted. Below are an example of each.
Class Method delete
# deleting a basic setting
c.delete('test')
# deleting a nested setting
c.delete(('nestedTest2', 'nested', 'test'))
del
Statement Method
# deleting a basic setting
del c['test']
# deleting a nested setting
del c['nestedTest2']['nested']['test']
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
Hashes for yet-another-json-config-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb8ec49b4c8ea94b1fe2cf60d57bb14042c0943a5a2ca7368113f19c424cad2d |
|
MD5 | c5801dfea822babcc873ec867242fcab |
|
BLAKE2b-256 | e59d4657fd5e24e9a3dcd49a48e67836b07084c72d12663dfa4f8db523af8d42 |
Hashes for yet_another_json_config-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67c4a563b7480e66eb6533e3b9bf770fc2195ca55df80f231822f529a0557c67 |
|
MD5 | df9a462cc9b51536c1629dc6a69834cf |
|
BLAKE2b-256 | dd13b1b0aa25a0dd2d6a5675983c457adc381712163f66b3d5ab81bb1885c7cb |