Skip to main content

Augmented python configparser

Project description

jconfigparser

Python PyPi License Black

`jconfigparser` is an extension of the `python` `configparser` standard module which adds the following features inspired by [`TOML`](https://github.com/toml-lang/toml):
  • Section name depth with dot notation: [a.b]
  • Values on right hand side can be everything that is understood by JSON.
  • Values that appear twice or more often are stored as a list, see example output below (this behavior is configurable).

Example

Say we have the following configuration file in test.jconf:

[atoms]
file:                          geometry.in
format:                        aims

[calculator.aims]
xc:                            pbesol
charge_mix_param:              0.3
sc_accuracy_rho:               1e-6

output: band  0     0     0     0.00  0.25  0.25  50   Gamma  Delta
output: band  0.00  0.25  0.25  0     0.5   0.5   50   Delta  X

[calculator.socketio]
port:                          null

[basissets.aims]
default:                       light

This file can be parsed with

import jconfigparser as jc

config = jc.Config('test.jconf')

config will be a modified dict that hold the information like

{
    "atoms": {"file": "geometry.in", "format": "aims"},
    "calculator": {
        "aims": {
            "xc": "pbesol",
            "charge_mix_param": 0.3,
            "sc_accuracy_rho": 1e-06,
            "output": [
                "band  0     0     0     0.00  0.25  0.25  50   Gamma  Delta",
                "band  0.00  0.25  0.25  0     0.5   0.5   50   Delta  X",
            ],
        },
        "socketio": {"port": None},
    },
    "basissets": {"aims": {"default": "light"}},
}

Furthermore, config supports

  • Attribute access, e.g., config.atoms.file
  • Write itself: config.write("new.jconf")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jconfigparser, version 0.1.1b2
Filename, size File type Python version Upload date Hashes
Filename, size jconfigparser-0.1.1b2-py3-none-any.whl (6.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size jconfigparser-0.1.1b2.tar.gz (5.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page