Skip to main content

Build Status

dynamic-json

Dynamic-json allows self-referential entries in a json file. It requires no dependencies, but lacks all the nice features of the yaml specification. If you prefer yaml then see [dynamic-yaml][dynamic-yaml].

Usage

The key feature that was introduced is the ability for a string scalar to reference other parts of the configuration tree. This is done using the Python string formatting syntax. The characters '{' and '}' enclose a reference to another entry in the configuration structure. The reference takes the form key1.key2 where key1 maps to another mapping object and can be found in the root mapping, and key2 can be found in key1's mapping object. Multiple levels of nesting can be used (eg. key1.key2.key3 etc...).

An example yaml configuration:

{
  "project_name": "hello-world",
  "dirs": {
    "home": "/home/user",
    "venv": "{dirs.home}/venvs/{project_name}",
    "data": "{dirs.venv}/data",
    "output": "{dirs.data}/output-{parameters.parameter1}-{parameters.parameter2}"
  },
  "parameters": {
    "parameter1": "a",
    "parameter2": "b"
  }
}

Reading in a json file:

import dynamic_json

with open('/path/to/file.json') as fileobj:
    cfg = dynamic_json.load(fileobj)
    assert cfg.dirs.venv == '/home/user/venvs/hello-world'
    assert cfg.dirs.output == '/home/user/venvs/hello-world/data/output-a-b'

As the variables are dynamically resolved, it is also possible to combine this with argparse:

import dynamic_json

from argparse import ArgumentParser

with open('/path/to/file.yaml') as fileobj:
    cfg = dynamic_json.load(fileobj)
    parser = ArgumentParser()
    parser.add_argument('--parameter1')
    parser.add_argument('--parameter2')
    parser.parse_args('--parameter1 c --parameter2 d'.split(), namespace=cfg.parameters)
    assert cfg.dirs.output == '/home/user/venvs/hello-world/data/output-c-d'

Installation

To install, simply run:

pip install dynamic-json

Restrictions

Due to the short amount of time I was willing to spend on working upon this, there are a few restrictions that I could not overcome.

  • Certain keys can only be used via __getitem__ and not __getattr__. Because dict comes with it's own set of attributes that are always resolved first, the values for the following keys must be gotten using the item getter rather than the attribute getter (eg. config['items'] vs. config.items):
    • append
    • extend
    • insert
    • remove
    • pop
    • clear
    • index
    • count
    • sort
    • reverse
    • copy

Metadata

Release files for dynamic-json 1.0.3

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

Source distribution (sdist)

Source distribution for dynamic-json 1.0.3
File Size Uploaded Provenance
dynamic-json-1.0.3.tar.gz 3.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dynamic-json 1.0.3
File Interpreter ABI Platform
dynamic_json-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / dynamic-json-1.0.3.tar.gz

Download URL dynamic-json-1.0.3.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c5585eb2aa91aa59663a5175b35cc5eb2e4fc0a64d257fc4df848ac0c880af44
BLAKE2b-256 checksum
How to use checksums
1c864c4986b252687b744f2710641d10874903aa127cc577585548ce9ac1ba7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.3

Release files / dynamic_json-1.0.3-py3-none-any.whl

Download URL dynamic_json-1.0.3-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3535ebddb850a71b8cceeb9b7ac2ad231cf05a463d1c6d24def483dce2a618e
BLAKE2b-256 checksum
How to use checksums
ea0b6e62f925d23d1fbc0be6f5f6a4f2603fff17ecf79d6059ad1dd30fc12847
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.3

Security for dynamic-json 1.0.3

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.

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files No provenance

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