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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file naapc-2.1.2.tar.gz.
File metadata
- Download URL: naapc-2.1.2.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58dd4565142cd6c0353ac5de6ffea63f3d064345651115a6cdf68b2a29e2fa50
|
|
| MD5 |
401aacda139d690f385c19a883e102a7
|
|
| BLAKE2b-256 |
a47ca0e263b564ccf81e2087d82ef69c12487413a1b21cef081b8c99a2b83dd0
|
File details
Details for the file naapc-2.1.2-py3-none-any.whl.
File metadata
- Download URL: naapc-2.1.2-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5120628a1b38db98f318fab65625798272235905635b88c66a017a0060880cca
|
|
| MD5 |
3e0fdac7d4769eb39a5b988747d9a1dc
|
|
| BLAKE2b-256 |
0420d7c36f95a1aacfb16678e837bd9caa8841705ba028ce3088564275fa7992
|