Skip to content

A simple config parser for Python, featuring basic type conversion & much accessibility.

License

Notifications You must be signed in to change notification settings

citharus/config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CONFIG

The config package provides a simple config parser with easier accessibility.

The Parser delivered with the config package provides a context manager and a variety of options. For easier accessibility, the Parser has the option to convert the parsed config to a nested namedtuple which contains the sections and their options.

Installation

pip install git+https://github.com/citharus/config.git

Example

The Parser with the default settings:

>>> from config import Parser

>>> with open('config.ini', 'r') as file:
        with Parser(file) as config:
            print(config)

{'SECTION': {'str': 'string', 'none': None, 'int': '1', 'float': '1.1', 'bool': 'yes'}}

The Parser with namedtuples enabled:

>> > from config import Parser

>> > with open("config.ini") as file:
    with Parser(file, is_namedtuple=True) as config:
        print(config)

CONFIG(SECTION=SECTION(str='string', none=None, int='1', float='1.1', bool='yes'))

The Parser with type conversion enabled:

>>> from config import Parser

>>> with open('config.ini', 'r') as file:
        with Parser(file, type_conversion=True) as config:
            print(config)

{'SECTION': {'str': 'string', 'none': None, 'int': 1, 'float': 1.1, 'bool': True}}