Skip to main content

A tool that extends configparser to enable enhanced processing of .ini files.

Project description

ActiveConfigParser

The ActiveConfigParser package provides extended handling of .ini files beyond what ConfigParser provides by adding an active syntax to embed operations with options.

For example, a standard .ini file is generally formatted like this:

[Section 1]
Foo: Bar
Baz: Bif

[Section 2]
Foo: Bar2
Bif: Baz

These files are used to organize sets of key - value pairs called “options” within groups called “sections”. In the example above there are two sections, “Section 1” and “Section 2”. Each of them contains two options where Section 1 has the keys ‘Foo’ and ‘Baz’ which are assigned the values ‘Bar’ and ‘Bif’, respectively. For more details on .ini files please see the documentation for ConfigParser.

Internally, these handlers methods defined according to a naming convention like handler_<operation>().

CPE only provides one pre-defined operation: use which is formatted as use TARGET: where param1 is the TARGET (there is no value field for this one). The TARGET paramter takes the name of a target section that will be loaded in at this point. This works in the same way a #include would work in C++ and serves to insert the contents or processing of the target section into this location.

The use operation is useful for .ini files for complex systems by allowing developers to create a common section and then have specializations where they can customize options for a given project. For example:

[COMMON]
Key C1: Value C1
Key C2: Value C2
Key C3: Value C3

[Data 1]
Key D1: Value D1
use COMMON
Key D2: Value D2

In this example, processing section Data 1 via CPE will result in the following options: Key D1: Value D1, Key C1: Value C1, Key C2: Value C2, Key C2: Value C2, Key D2: Value D2.

An alternative way of looking at this is it’s like having a .ini file that is effectively the following where the use operations are replaced with the results of a Depth-First expansion of the linked sections:

[COMMON]
Key C1: Value C1
Key C2: Value C2
Key C3: Value C3

[Data 1]
Key D1: Value D1
Key C1: Value C1
Key C2: Value C2
Key C3: Value C3
Key D2: Value D2

Linked Projects

Examples

Here we show some example usages of ActiveConfigParser. Additional examples can be found in the examples/ directory of the repository.

Example 1

[SECTION-A]
key-A1: value-A1
key-A2: value-A2
key-A3: value-A3

[SECTION-B]
use SECTION-A
key-B1: value-B1

In this example, the entry use SECTION-A that is inside [SECTION-B] instructs the core parser to recurse into [SECTION-A] and process it before moving on with the rest of the entries in [SECTION-B]. In this example the following code could be used to parse SECTION-B. ActiveConfigParser.activeconfigparserdata['SECTION-B'] would return the following result:

>>> from activeconfigparser import ActiveConfigParser
>>> cpe = ActiveConfigParser(filename='config.ini')
>>> cpe.activeconfigparserdata['SECTION-B']
{
    'key-A1': 'value-A1',
    'key-A2': 'value-A2',
    'key-A3': 'value-A3',
    'key-B1': 'value-B1',
}

Updates

See the CHANGELOG for information on changes.

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

activeconfigparser-0.9.0.1.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

activeconfigparser-0.9.0.1-py3-none-any.whl (55.4 kB view details)

Uploaded Python 3

File details

Details for the file activeconfigparser-0.9.0.1.tar.gz.

File metadata

  • Download URL: activeconfigparser-0.9.0.1.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for activeconfigparser-0.9.0.1.tar.gz
Algorithm Hash digest
SHA256 d11c725089847dffeb77eec2187dbc5cd13d134a7a15f6cc4d9a56fcf9dce030
MD5 74f8c4dc90ba9ea9febf3928c99bb5e3
BLAKE2b-256 5e7d734b3ee1edf9a9a0504e64810ee9cec08c32409965d94a9aed3b587510ce

See more details on using hashes here.

File details

Details for the file activeconfigparser-0.9.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for activeconfigparser-0.9.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 67277e2e41e403143f8ce878bfe65c1abde9249f79669479c13acd8fdff95cc7
MD5 e7dad1e7b65787e7b976cc681921e305
BLAKE2b-256 46189d8ca3e5ca781f8a9bf2718c3c5a83e571d60fa7f0379e105bf49893f617

See more details on using hashes here.

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