pjconf
A simple configuration interface to use JSON files as configuration files.
Installation
PJC is installed via pip.
pip install pjconf
Usage
Loading configuration is straightforward, just import and point to your json file.
import pjconf as pjc
# Load a json file as a configuration dictionary.
config = pjc.load_config('config.json')
# or, load a configuration file with an optional default set of configuration elsewhere
config = pjc.load_config('defaults.json', 'config.json', ignore_missing=True)
Configuration files are loaded in a cascading sequence, multiple positional filepaths are loaded and override/update the previous keys. Setting ignore_missing=True will allow for a flexible resolve of optional configuration; disabling it will raise a FileNotFoundError on the first file it can't find.
Accessing configuration uses a get() method, with a cool dot-recursive syntax, optional defaults and runtime type-casting.
Let's assume the following configuration file.
{
"opt1": true
"opt2": 0.1
"opt3": {
"subopt1": "hello"
}
}
You can use the following syntax to access your configuration.
# Access a simple option
opt1 = config.get('opt1')
# True
# Access a recursive (nested) option
subopt1 = config.get('opt3.subopt1')
# "hello"
# Try to access a missing option, but provide a default
missing_opt = config.get('missing', default=True)
# True
# Runtime type-casting
opt2asint = config.get('opt2', cast=int)
# 0
For the last example, the cast argument takes a callable with a single parameter - you can be as simple or as complicated (i.e. lambdas or defined functions) as you like.
Metadata
Release files for pjconf 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pjconf-1.0.0.tar.gz | 3.9 kB | Without provenance | Details |
Release files / pjconf-1.0.0.tar.gz
| Download URL | pjconf-1.0.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
430505161239edd9725d57be2beb6c8cc961fe9c41e2a9a4d2a3645212b18bc4
|
|
BLAKE2b-256 checksum How to use checksums |
5ec4612b600a3fcff8e766c03b3116e02835856ecedb131e8cdcb1958450450b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Security for pjconf 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.