Skip to main content

By default, configparser only loads values from ‘vars’, ‘section’, and then ‘default_section’. This extension allows for nested sections by use of a section splitter (default ‘.’) and attempts to find values from ‘vars’, then ‘section’, then its logical parents, and finally ‘default_section’.

For example, given the configuration below:

[DEFAULT]
alpha=first level

[section]
beta=second level

[section.subsection]
gamma=third level

the default configparser would behave like:

>>> settings = configparser.ConfigParser()
>>> settings.read('config.ini')
['config.ini']
>>> settings.get('section.subsection', 'alpha')
first level
>>> settings.get('section.subsection', 'beta')
None
>>> settings.get('section.subsection', 'gamma')
third level

Instead, in this extension, the behaviour would be:

>>> settings = nestedconfigparser.NestedConfigParser()
>>> settings.read('config.ini')
['config.ini']
>>> settings.get('section.subsection', 'alpha')
first level
>>> settings.get('section.subsection', 'beta')
second level
>>> settings.get('section.subsection', 'gamma')
third level

This extensions supports theoretically unlimited levels of nesting. It also does not require each level of the subsection to exist for the case where a section has no additional configurations.

Note: this extension intentionally does not raise a NoSectionError if a section does not exist when using ‘nestedconfigparser.NestedConfigParser().get(section, option)’. This is because it will attempt to fallback to higher sections and avoids potentially empty sections that don’t have any added configurations at the highest subsection.

Release files for allya.nestedconfigparser 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for allya.nestedconfigparser 0.1.0
File Interpreter ABI Platform
allya.nestedconfigparser-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / allya.nestedconfigparser-0.1.0-py3-none-any.whl

Download URL allya.nestedconfigparser-0.1.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ff13cae92f453ebdb98471398394ad8418fbc2b97d3a24defc3ed76a84b06d1
BLAKE2b-256 checksum
How to use checksums
8349029660b57f095dd8e1800e993605c776f62d46604f34f287ceed59820414
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page