Skip to main content

ExtendParser extend stanrad ConfigParser for some functionality.

Project description

Extend parser is set of ConfigParser extensions. Get and Include extensions are added to one class ExtendParser. For more details see source code, or use help.


2018, see AUTHORS for more details


BSD, see LICENSE for more details



>>> from extendparser import ExtendParser
>>> cp = ExtendParser()


Include class can append content from other configuration files. Let’s have these configuration files:

# test.ini
string = value
.include numbers.ini
# numbers.ini
integer = 42
.include const.ini
# const.ini
pi = 3.14

Here is the string buffer which ConfiguratinParser will read:

# test.ini
string = value
# numbers.ini
integer = 42
# const.ini
pi = 3.14


Get class has two smart methods get_option and get_section to get value(s) in any type you want.

>>> from extendparser.get import Get
>>> cp = Get()
>>> print(cp.get_option("test", "number", target=int, fallback=1))
>>> print(cp.get_option("test", "list", target=list, fallback=["a"],
...                      delimiter=','))
>>> cp.add_section("test")
>>> cp.set("test", "tuple", "a:b:c")
>>> print(cp.get_option("test", "tuple", target=tuple, delimiter=':'))
('a', 'b', 'c')
>>> print(cp.get_section("test", (("tuple", tuple, tuple(), ':'),
...                               ("string", str, "value"))))
{'tuple': ('a', 'b', 'c'), 'string': 'value'}


Environ module has two classes, which extend ConfigParser to read environment variables. There is EnvironFirst class, which read environment variables first, and then use original get method.

>>> from os import environ
>>> from configparser import ConfigParser
>>> from extendparser.environ import EnvironFirst
>>> cp = EnvironFirst()
>>> cp.add_section("test")
>>> cp.getint("test", "number", fallback=1)
>>> cp.set("test", "number", "7")
>>> cp.getint("test", "number")
>>> environ["TEST_NUMBER"] = "42"
>>> cp.getint("test", "number")

Next EnvironLast class use environment variable as fallback for original get method.

>>> from os import environ
>>> from configparser import ConfigParser
>>> from extendparser.environ import EnvironLast
>>> cp = EnvironLast()
>>> cp.add_section("test")
>>> cp.getfloat("test", "float", fallback=1.0)
>>> environ["TEST_FLOAT"] = "42"
>>> cp.getfloat("test", "float", fallback=1)
>>> cp.set("test", "float", "3.14")
>>> cp.getfloat("test", "float")


~$ pip install extendparser

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

extendparser-0.3.1.tar.gz (8.7 kB view hashes)

Uploaded source

Built Distribution

extendparser-0.3.1-py3-none-any.whl (11.4 kB view hashes)

Uploaded py3

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