python INI configuration library
conficus is a python toml configuration wrapper. providing some extra type coercions (e.g. str -> Path) easier access and section inheritance.
conficus python 3.6+.
Install conficus with pip.
pip install conficus
>>> >>> import conficus >>>
Configurations can be loaded directly from a string variable or read via file path string or Path object:
>>> config = conficus.load('/Users/mgemmill/config.ini', toml=True) >>>
conficus will also read a path from an environment variable:
>>> config = conficus.load('ENV_VAR_CONFIG_PATH') >>>
Accessing nested sections is made easier with chained selectors:
>>> # regular dictionary access: ... >>> config['app']['debug'] True >>> >>> # chained selector access: ... >>> config['app.debug'] True
Inheritance pushes parent values down to any child section:
# config.ini [app] debug =
true[email] _inherit = 0host = "smtp.mailhub.com"port = 2525sender = "email@example.com"[email.alert] to = ["firstname.lastname@example.org"]subject = "THIS IS AN ALERT"body = "Alerting!"
It is turned on via the inheritance option:
>>> config = conficus.load("config.ini", inheritance=True)
Sub-sections will now contain parent values:
>>> alert_config = config["email.alert"] >>> alert_config["host"] >>> "smtp.mailhub.com" >>> alert_config["subject"] >>> "THIS IS AN ALERT"
Inheritence can be controled per section via the _inherit option. _inherit = 0 will block the section from inheriting parent values. _inherit = 1 would only allow inheritance from the sections immediate parent; _inherit = 2 would allow both the immediate parent and grandparent inheritance.
_inherit values are stripped from the resulting configuration dictionary.
Additional Conversion Options
In addition to toml’s standard type conversions, conficus has two builtin conversion options and also allows for adding custom conversions.
Conversions only work with string values.
The pathlib option will convert any toml string value that looks like a path to a python pathlib.Path object:
>>> config = conficus.load("path = '/home/user/.dir'", pathlib=True) >>> isinstance(config["path"], Path) >>> True
The decimal option will convert any toml string value that matches \d+\.\d+ to a python Decimal object:
>>> config = conficus.load("number = '12.22'", decimal=True) >>> isinstance(config["number"], Decimal) >>> True
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.