inischema allows the definition of schemas for .ini configuration files.
Consider this sample schema:
>>> schema = '''
... [first]
... value1 = int
... value2 = string
... value3 = float
... value4 = listofstrings
... value5 = listofints
...
... [second]
... value1 = string
... value2 = int
... '''
This schema defines the sections, names and types of values expected in a schema file.
Using a concrete configuration, we can then use the schema to extract values:
>>> config = '''
... [first]
... value1 = 2
... value2 = three
... value3 = 4.4
... value4 = five six seven
... value5 = 8 9
...
... [second]
... value1 = ten
... value2 = 100
... value3 = what?
... '''
>>> result = parse_config(schema, config)
>>> from pprint import pprint
>>> pprint(result)
{'first': {'value1': 2,
'value2': 'three',
'value3': 4.4,
'value4': ['five', 'six', 'seven'],
'value5': [8, 9]},
'second': {'value1': 'ten', 'value2': 100, 'value3': 'what?'}}
Values in the config file that are not in the schema are assumed to be strings.
This module is used in nolearn.console to allow for convenient passing of values from .ini files as function arguments for command line scripts.