Name | naapc JSON |
Version |
2.1.1
JSON |
| download |
home_page | |
Summary | Nested Automated Argument Parsing Configuration (NAAPC). |
upload_time | 2023-09-27 12:31:51 |
maintainer | |
docs_url | None |
author | |
requires_python | ==3.10.* |
license | MIT License Copyright (c) 2022 Bai Huanyu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
configuration
config
dictionary
nested
argument parsing
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Nested Automated Argument Parsing Configuration (NAAPC)
[NAAPC](https://pypi.org/project/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
```bash
pip install naapc
```
Or from source code:
```bash
pip install .
```
## Typical Usage.
## ndict Usages
for a sample configuration test.yaml file:
```yaml
task:
task: classification
train:
loss_args:
lr: 0.1
```
and a sample list configuration test_list.yaml file:
```yaml
l:
- d:
task:
task: classification
- d:
train:
loss_args:
lr: 0.1
```
```python
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
```python
NestedOrDict = Union[ndict, dict]
```
Raw data
{
"_id": null,
"home_page": "",
"name": "naapc",
"maintainer": "",
"docs_url": null,
"requires_python": "==3.10.*",
"maintainer_email": "",
"keywords": "configuration,config,dictionary,nested,argument parsing",
"author": "",
"author_email": "Bai Huanyu <eiphnix@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/51/66/55f7f66d699be448081cc8b224e64f37eeb7bcd7624d9aa1ce1878944f42/naapc-2.1.1.tar.gz",
"platform": null,
"description": "# Nested Automated Argument Parsing Configuration (NAAPC)\n[NAAPC](https://pypi.org/project/naapc/) contains two classes: NConfig and NDict.\nNDict provides method to easily manipulate nested dictionaries.\nNConfig is a subclass of NDict and can **automatically modify configurations according to CLI arguments**.\n\n## Installation\n```bash\npip install naapc\n```\n\nOr from source code:\n```bash\npip install .\n```\n\n## Typical Usage.\n## ndict Usages\nfor a sample configuration test.yaml file:\n```yaml\ntask:\n task: classification\ntrain:\n loss_args:\n lr: 0.1\n```\nand a sample list configuration test_list.yaml file:\n```yaml\nl:\n- d:\n task:\n task: classification\n- d:\n train:\n loss_args:\n lr: 0.1\n```\n\n```python\nfrom naapc import ndict\n\nwith open(\"test.yaml\", \"r\") as f:\n raw = yaml.safe_load(f)\nnd = ndict(raw[\"d\"], delimiter=\";\")\nnd1 = ndict.from_flatten_dict(nd.flatten_dict) # nd1 == nd\nnd2 = ndict.from_list_of_dict(raw[\"l\"]) # nd2 == nd1 == nd\n\n\"task;path\" in nd # \"task\" in raw and \"path\" in raw[\"task\"]\ndel nd[\"task;path\"] # del raw[\"task][\"path]\nnd[\"task;path\"] = \"cwd\" # raw[\"task\"][\"path\"] = Path(\".\").absolute()\nnd.flatten_dict # {\"task;task\": \"classification\", \"train;loss_args;lr\": 0.1}\nnd.flatten_dict_split # raw[\"l\"]\nnd.paths # [\"task\", \"task;task\", \"train\", \"train;loss_args\", \"train;loss_args;lr\"]\nnd.get(\"task;seed\", 1) # raw[\"task\"].get(\"seed\", 1)\nnd.raw_dict # raw\nnd.size # len(nd.flatten_dict)\nnd.update({\"task;here\": \"there\"}) # raw[\"task][\"here] = \"there\nnd.items() # raw.items()\nnd.keys() # raw.keys()\nnd.values() # raw.values()\nlen(nd) # len(raw)\nbool(nd) # len(nd) > 0\nnd1 == nd # nd1.flatten_dict == nd.flatten_dict\nnd1[\"task;path\"] = \"xcwd\"\nnd1[\"task;extra\"] = \"ecwd\"\nnd[\"train;epochs\"] = 100\nnd.diff(nd1) # {\"task;path\": (\"cwd\", \"xcwd\"), \"task;extra\": (None, ecwd), \"train;epochs\": (100, None)}\n```\n\nCheck test/test_ndict.py for detailed usage.\n\n## Known Issues\nAssign a list of ndict won't flatten them. Try to avoid using list.\n\n## Typing\nAdd a type\n```python\nNestedOrDict = Union[ndict, dict]\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2022 Bai Huanyu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Nested Automated Argument Parsing Configuration (NAAPC).",
"version": "2.1.1",
"project_urls": {
"repository": "https://github.com/eiphy/naapc"
},
"split_keywords": [
"configuration",
"config",
"dictionary",
"nested",
"argument parsing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e8a92cc82bed66fc8777fd8615fd27a5306f1da7045d70766eb69a97d418744e",
"md5": "248f0494ab109758a689ab246015869d",
"sha256": "68706f472150745e2d74a16effda94bcb741c93aa991118fe2956d87330c1c45"
},
"downloads": -1,
"filename": "naapc-2.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "248f0494ab109758a689ab246015869d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "==3.10.*",
"size": 10505,
"upload_time": "2023-09-27T12:31:50",
"upload_time_iso_8601": "2023-09-27T12:31:50.036186Z",
"url": "https://files.pythonhosted.org/packages/e8/a9/2cc82bed66fc8777fd8615fd27a5306f1da7045d70766eb69a97d418744e/naapc-2.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "516655f7f66d699be448081cc8b224e64f37eeb7bcd7624d9aa1ce1878944f42",
"md5": "8db1e5fdad15b01d83c13997f9a14f55",
"sha256": "fd9934b077702962f1bc74bbe49d3e6425a4938ee043f65377a7a61710ca4d89"
},
"downloads": -1,
"filename": "naapc-2.1.1.tar.gz",
"has_sig": false,
"md5_digest": "8db1e5fdad15b01d83c13997f9a14f55",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "==3.10.*",
"size": 12522,
"upload_time": "2023-09-27T12:31:51",
"upload_time_iso_8601": "2023-09-27T12:31:51.732106Z",
"url": "https://files.pythonhosted.org/packages/51/66/55f7f66d699be448081cc8b224e64f37eeb7bcd7624d9aa1ce1878944f42/naapc-2.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-27 12:31:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "eiphy",
"github_project": "naapc",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "naapc"
}