Skip to main content

Nested Automated Argument Parsing Configuration (NAAPC).

Project description

Nested Automated Argument Parsing Configuration (NAAPC)

NAAPC contains two classes: NConfig and NDict. NDict provides method to easily manipulate nested dictionaries. NConfig is a subclass of NDict and can automatically modify configurations according to CLI arguments.

Installation

pip install naapc

Or from source code:

pip install .

Typical Usage.

ndict Usages

for a sample configuration test.yaml file:

task:
  task: classification
train:
  loss_args:
    lr: 0.1

and a sample list configuration test_list.yaml file:

l:
- d:
    task:
      task: classification
- d:
    train:
      loss_args:
        lr: 0.1
from naapc import ndict

with open("test.yaml", "r") as f:
  raw = yaml.safe_load(f)
nd = ndict(raw["d"], delimiter=";")
nd1 = ndict.from_flatten_dict(nd.flatten_dict) # nd1 == nd
nd2 = ndict.from_list_of_dict(raw["l"]) # nd2 == nd1 == nd

"task;path" in nd                      # "task" in raw and "path" in raw["task"]
del nd["task;path"]                    # del raw["task]["path]
nd["task;path"] = "cwd"                # raw["task"]["path"] = Path(".").absolute()
nd.flatten_dict                        # {"task;task": "classification", "train;loss_args;lr": 0.1}
nd.flatten_dict_split                  # raw["l"]
nd.paths                               # ["task", "task;task", "train", "train;loss_args", "train;loss_args;lr"]
nd.get("task;seed", 1)                 # raw["task"].get("seed", 1)
nd.raw_dict                            # raw
nd.size                                # len(nd.flatten_dict)
nd.update({"task;here": "there"})      # raw["task]["here] = "there
nd.items()                             # raw.items()
nd.keys()                              # raw.keys()
nd.values()                            # raw.values()
len(nd)                                # len(raw)
bool(nd)                               # len(nd) > 0
nd1 == nd                              # nd1.flatten_dict == nd.flatten_dict
nd1["task;path"] = "xcwd"
nd1["task;extra"] = "ecwd"
nd["train;epochs"] = 100
nd.diff(nd1)                   # {"task;path": ("cwd", "xcwd"), "task;extra": (None, ecwd), "train;epochs": (100, None)}

Check test/test_ndict.py for detailed usage.

Known Issues

Assign a list of ndict won't flatten them. Try to avoid using list.

Typing

Add a type

NestedOrDict = Union[ndict, dict]

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

naapc-2.0.2.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

naapc-2.0.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file naapc-2.0.2.tar.gz.

File metadata

  • Download URL: naapc-2.0.2.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for naapc-2.0.2.tar.gz
Algorithm Hash digest
SHA256 8b8db9a680c31ea45766e8c1dce1339f9e130039cbf8b043a890f5d1f87b44ed
MD5 373fd83fe4e7e655acf3f935cf2497ae
BLAKE2b-256 65346e3fade1c2865ab84bcddfc59f66015707005075d6e80349c10824485ce1

See more details on using hashes here.

File details

Details for the file naapc-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: naapc-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for naapc-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3bf7b231730439e4d967bff6ded5c026dcb9b1d9d5dd30b56a13d1f6fd5bdc2c
MD5 d7d95bc295ea599d2cef3011c060fd10
BLAKE2b-256 20b956b3d22b6a316ce908991c5861696545ffba1c8f2deb557e52ae8ff38e55

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