Python Config Parser Library
confparser is a config parser by yml file or dictionary.
In confparser, you can easily access to value through dot notation.
Like, conf.debug, conf.server.dev.debug.
Installation
pip3 install confparser
Usage
Config by .yml file
Create yml file
debug: True
server:
dev:
debug: True
port: 8000
prod:
debug: False
port: 80
Import confparser and insert your yml file.
from confparser import ConfParser
config = ConfParser(path='./config.yml').to_obj()
print(config)
# {'debug': True, 'server': {'dev': {'debug': True, 'port': 8000}, 'prod': {'debug': False, 'port': 80}}}
print(config.debug)
# True
print(config.server)
# {'dev': {'debug': True, 'port': 8000}, 'prod': {'debug': False, 'port': 80}}
print(config.server.dev)
# {'debug': True, 'port': 8000}
print(config.server.dev.debug)
# True
print(config.server.dev.port)
# 8000
print(config.server.prod.debug)
# False
print(config.server.prod.port)
# 80
Config by dictionary
Import confparser and insert your dictionary.
from confparser import ConfParser
conf_dict = {
'debug': True,
'server': {
'dev': {
'debug': True,
'port': 8000,
},
'prod': {
'debug': False,
'port': 80,
},
}
}
config = ConfParser(conf_dict=conf_dict).to_obj()
print(config)
# {'debug': True, 'server': {'dev': {'debug': True, 'port': 8000}, 'prod': {'debug': False, 'port': 80}}}
print(config.debug)
# True
print(config.server)
# {'dev': {'debug': True, 'port': 8000}, 'prod': {'debug': False, 'port': 80}}
print(config.server.dev)
# {'debug': True, 'port': 8000}
print(config.server.dev.debug)
# True
print(config.server.dev.port)
# 8000
print(config.server.prod.debug)
# False
print(config.server.prod.port)
# 80
Note
path and conf_dict cannot be used at once.
Dependencies
To use parsing yml file, pyyaml is needed.
But it will be install automatically with confparser so you don't have to install manually.
Release files for confparser 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| confparser-0.1.7.tar.gz | 3.5 kB | Details |
Release files / confparser-0.1.7.tar.gz
| Download URL | confparser-0.1.7.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d249a2c7eaf5c4a041f8499a0da37f9dba13c3faf567eea210ae9fc3dc30deb
|
|
BLAKE2b-256 checksum How to use checksums |
1f8800f4a4d3b707432e031c9d30f0af87a4b50c2641f6387188540840039894
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.6
|