Skip to main content

Build Status Coverage

A straightforward and unambiguous config file parser.

This package was originally based on the configparser module that comes in the standard python distribution but has been almost entirely rewritten.

The main branch won’t support python 2 as it is missing keyword only arguments and ChainMap is not in the standard library. If you need legacy support then there are a couple of forks which look like they do the job.

Installation

Available on pypi as json-config-parser

To install run

pip install json-config-parser

Alternatively grab the code from github and run:

python setup.py install

Syntax

Files are structured using square bracket sections, # comments and $key = $value options. Option values are written in json and can lists and dictionaries be spread over any number of lines. To keep parsing simple and files neat, comments, section headers and keys can not be indented and no whitespace is allowed on empty lines.

Comments start at the beginning of a line with a # symbol and extend to the line’s end.

Usage

cfg = JSONConfigParser()

cfg.read_string("""
[section]
number = 3.141592654
dictionary = {"key": "value"}
list = [1,
        2,
        3]
nested = {"list": [1,2,3]}
true = true
none = null

[DEFAULT]
# settings in the default section are inherited
# by all other sections.
default-setting = "default"
""")

# read a setting
cfg.get("section", "number")

# read a setting using index notation
cfg["section"]["true"]

# settings inherited from DEFAULT
cfg.get("section", "default-setting")

Bugs

Please report any problems on the bugtracker and I will do my best to fix them. Pull requests are also welcome.

Metadata

Release files for json-config-parser 0.1.2

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

Source distribution (sdist)

Source distribution for json-config-parser 0.1.2
File Size Uploaded
json-config-parser-0.1.2.tar.gz 2.1 kB Details

Release files / json-config-parser-0.1.2.tar.gz

Download URL json-config-parser-0.1.2.tar.gz
Size 2.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8afa0a2926d8fbfe051192847ee84c06f9d511a3016a2f5ec31139205c495eb4
BLAKE2b-256 checksum
How to use checksums
628861546c8453d39b15b8063d3049663ed4118f12c8c39aea74bb23dc58b16e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.2

1 release file

0.0.1

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