INI-files parser with schemes and types
Application settings must be simple! In it should be a code or complex structures. Must be only a simple types.
JSON?
JSON is uncomfortable and unextendable.
YAML?
The YAML is like a garden of rakes. It's very complex format. I do not need all it's features.
- Configparser is ugly;
- Configparser is overengineered;
- Configparser does not have type casting;
- Configparser does not have type checking;
- Configparser is... configparser.
| boolean: | simple |
|---|---|
| int: | simple numeric type, e.g. |
| float: | float type, e.g. |
| string: | strings always uses quotes, e.g. |
| datetime: | datetime formated as ISO 8601
When specifying the time, you can set timezone as E.g.:
|
| timedelta: | durations:
|
| list: | list of values: key =
"string value"
2005-01-13 18:00:05
13 |
$ cat tests/test.ini
# first comment
[first]
boolean = false
integer = 13
[second]
; second comment
boolean = true
string = "some string"
[complex]
list =
"string"
"string too"
"else string">>> from zini import Zini
>>> ini = Zini()
>>> result = ini.read('tests/test.ini')
>>> isinstance(result, dict)
True
>>> result['first']['boolean'] is False # automatic type casting
True
>>> result['first']['integer'] == 13
True
>>> result['second']['string'] == "some string"
True
>>> result['complex']['list'] == ["string", "string too", "else string"]
True>>> from zini import Zini
>>> ini = Zini()
>>> ini['first']['integer'] = str # set type
>>> result = ini.read('tests/test.ini')
zini.ParseError: error in line 3: 'integer = 13'>>> from zini import Zini
>>> ini = Zini()
>>> ini['second']['boolean'] = "string" # set type and default value
>>> result = ini.read('tests/test.ini')
zini.ParseError: error in line 7: 'boolean = true'>>> import zini
>>> ini = zini.Zini()
>>> ini['third']['generic'] = [str]
>>> result = ini.read('tests/test.ini')
ParseError: error in line 20: ' 10'