Skip to main content

Python config parser library

Project description

Python Config Parser Library

license pypi pyversions badge

confparser is a pure 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

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

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.

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

confparser-0.1.2.tar.gz (3.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page