Name | dictIO JSON |
Version |
0.4.1
JSON |
| download |
home_page | None |
Summary | Python package to read, write and manipulate dictionary text files. Supports dictIOs native file format, as well as JSON, XML and OpenFOAM. |
upload_time | 2025-01-18 13:56:28 |
maintainer | None |
docs_url | None |
author | None |
requires_python | <3.14,>=3.10 |
license | MIT License Copyright (c) 2024 [DNV](https://www.dnv.com) [open source](https://github.com/dnv-opensource) 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 |
dict
dictio
dictparser
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
[](https://pypi.python.org/pypi/dictIO)
[](https://pypi.python.org/pypi/dictIO)
[](https://github.com/dnv-opensource/dictIO/blob/main/LICENSE)

[][dictIO_docs]
# dictIO
dictIO is a Python package to read, write and manipulate dictionary text files.
It was designed to leverage the versatility of text based dictionary files, or 'dict files' in short, while easing their use in Python through seamless support for Python dicts.
dictIO supports
* reading and writing Python dicts in dict files.
* usage of references and expressions in dict files, dynamically resolved during reading.
* usage of cascaded dict files, allowing separation of a case-agnostic configuration dict and its case-specific parameterization: baseDict + paramDict = caseDict
Further, dictIO
* is widely tolerant in reading different flavours (quotes, preserving comments, etc.)
* can read and write also JSON, XML and OpenFOAM (with some limitations)
## Installation
```sh
pip install dictIO
```
## Usage Example
dictIO's core class is `SDict`, a generic data structure for serializable dictionaries. <br>
`SDict` inherits from Python's builtin `dict`. It can hence be used transparently in any context where a `dict` or any other `MutableMapping` type is expected.
You can use `SDict` the same way you use `dict`. E.g. you can pass a dict literal to its constructor:
```py
from dictIO import SDict
my_dict: SDict[str, int] = SDict(
{
"foo": 1,
"bar": 2,
}
)
```
The simplest way to to dump and load a dict to / from a file, is to use SDict's `dump()` and `load()` instance methods:
To dump `my_dict` to a file, use `.dump()`:
```py
my_dict.dump("myDict")
```
To load the formerly dumped file into a new dict, use `.load()`:
```py
my_dict_loaded: SDict[str, int] = SDict().load("myDict")
```
In cases where you need more control over how dict files are read and written, <br>
dictIO's `DictReader` and `DictWriter` classes offer this flexibility, while still maintaining a simple and high level API:
```py
from dictIO import DictReader, DictWriter
my_dict = DictReader.read('myDict')
DictWriter.write(my_dict, 'parsed.myDict')
```
The above example reads a dict file, merges any (sub-)dicts included through #include directives, evaluates expressions contained in the dict,
and finally saves the read and evaluated dict with prefix 'parsed' as 'parsed.myDict'.
This sequence of reading, evaluating and writing a dict is also called 'parsing' in dictIO.
Because this task is so common, dictIO provides a convenience class for it:
Using `DictParser.parse()` the above task can be accomplished in one line of code:
```py
from dictIO import DictParser
DictParser.parse('myDict')
```
The `parse` operation can also be executed from the command line, using the 'dictParser' command line script installed with dictIO:
```sh
dictParser myDict
```
_For more examples and usage, please refer to dictIO's [documentation][dictIO_docs]._
## File Format
The native file format used by dictIO shares, by intention, some commonalities with the [OpenFOAM](https://www.openfoam.com/documentation/guides/latest/doc/openfoam-guide-input-types.html) file format, but is kept simpler and more tolerant to different flavours of string formatting.
With some limitations, dictIO supports also reading from and writing to [OpenFOAM](https://www.openfoam.com/documentation/guides/latest/doc/openfoam-guide-input-types.html), [Json](https://www.json.org/json-en.html) and [XML](https://www.w3.org/XML/).
_For a detailed documentation of the native file format used by dictIO, see [File Format](fileFormat.rst) in [dictIO's documentation][dictIO_docs] on GitHub Pages._
## Development Setup
### 1. Install uv
This project uses `uv` as package manager.
If you haven't already, install [uv](https://docs.astral.sh/uv), preferably using it's ["Standalone installer"](https://docs.astral.sh/uv/getting-started/installation/#__tabbed_1_2) method: <br>
..on Windows:
```sh
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```
..on MacOS and Linux:
```sh
curl -LsSf https://astral.sh/uv/install.sh | sh
```
(see [docs.astral.sh/uv](https://docs.astral.sh/uv/getting-started/installation/) for all / alternative installation methods.)
Once installed, you can update `uv` to its latest version, anytime, by running:
```sh
uv self update
```
### 2. Install Python
This project requires Python 3.10 or later. <br>
If you don't already have a compatible version installed on your machine, the probably most comfortable way to install Python is through `uv`:
```sh
uv python install
```
This will install the latest stable version of Python into the uv Python directory, i.e. as a uv-managed version of Python.
Alternatively, and if you want a standalone version of Python on your machine, you can install Python either via `winget`:
```sh
winget install --id Python.Python
```
or you can download and install Python from the [python.org](https://www.python.org/downloads/) website.
### 3. Clone the repository
Clone the dictIO repository into your local development directory:
```sh
git clone https://github.com/dnv-opensource/dictIO path/to/your/dev/dictIO
```
Change into the project directory after cloning:
```sh
cd dictIO
```
### 4. Install dependencies
Run `uv sync` to create a virtual environment and install all project dependencies into it:
```sh
uv sync
```
> **Note**: Using `--no-dev` will omit installing development dependencies.
> **Note**: `uv` will create a new virtual environment called `.venv` in the project root directory when running
> `uv sync` the first time. Optionally, you can create your own virtual environment using e.g. `uv venv`, before running
> `uv sync`.
### 5. (Optional) Activate the virtual environment
When using `uv`, there is in almost all cases no longer a need to manually activate the virtual environment. <br>
`uv` will find the `.venv` virtual environment in the working directory or any parent directory, and activate it on the fly whenever you run a command via `uv` inside your project folder structure:
```sh
uv run <command>
```
However, you still _can_ manually activate the virtual environment if needed.
When developing in an IDE, for instance, this can in some cases be necessary depending on your IDE settings.
To manually activate the virtual environment, run one of the "known" legacy commands: <br>
..on Windows:
```sh
.venv\Scripts\activate.bat
```
..on Linux:
```sh
source .venv/bin/activate
```
### 6. Install pre-commit hooks
The `.pre-commit-config.yaml` file in the project root directory contains a configuration for pre-commit hooks.
To install the pre-commit hooks defined therein in your local git repository, run:
```sh
uv run pre-commit install
```
All pre-commit hooks configured in `.pre-commit-config.yaml` will now run each time you commit changes.
pre-commit can also manually be invoked, at anytime, using:
```sh
uv run pre-commit run --all-files
```
To skip the pre-commit validation on commits (e.g. when intentionally committing broken code), run:
```sh
uv run git commit -m <MSG> --no-verify
```
To update the hooks configured in `.pre-commit-config.yaml` to their newest versions, run:
```sh
uv run pre-commit autoupdate
```
### 7. Test that the installation works
To test that the installation works, run pytest in the project root folder:
```sh
uv run pytest
```
## Meta
Copyright (c) 2024 [DNV](https://www.dnv.com) AS. All rights reserved.
Frank Lumpitzsch - [@LinkedIn](https://www.linkedin.com/in/frank-lumpitzsch-23013196/) - frank.lumpitzsch@dnv.com
Claas Rostock - [@LinkedIn](https://www.linkedin.com/in/claasrostock/?locale=en_US) - claas.rostock@dnv.com
Seunghyeon Yoo - [@LinkedIn](https://www.linkedin.com/in/seunghyeon-yoo-3625173b/) - seunghyeon.yoo@dnv.com
Distributed under the MIT license. See [LICENSE](LICENSE.md) for more information.
[https://github.com/dnv-opensource/dictIO](https://github.com/dnv-opensource/dictIO)
## Contributing
1. Fork it (<https://github.com/dnv-opensource/dictIO/fork>)
2. Create an issue in your GitHub repo
3. Create your branch based on the issue number and type (`git checkout -b issue-name`)
4. Evaluate and stage the changes you want to commit (`git add -i`)
5. Commit your changes (`git commit -am 'place a descriptive commit message here'`)
6. Push to the branch (`git push origin issue-name`)
7. Create a new Pull Request in GitHub
For your contribution, please make sure you follow the [STYLEGUIDE](STYLEGUIDE.md) before creating the Pull Request.
<!-- Markdown link & img dfn's -->
[dictIO_docs]: https://dnv-opensource.github.io/dictIO/README.html
[ospx_docs]: https://dnv-opensource.github.io/ospx/README.html
[farn_docs]: https://dnv-opensource.github.io/farn/README.html
Raw data
{
"_id": null,
"home_page": null,
"name": "dictIO",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.14,>=3.10",
"maintainer_email": "Claas Rostock <claas.rostock@dnv.com>",
"keywords": "dict, dictIO, dictParser",
"author": null,
"author_email": "Frank Lumpitzsch <frank.lumpitzsch@dnv.com>, Claas Rostock <claas.rostock@dnv.com>, Seunghyeon Yoo <seunghyeon.yoo@dnv.com>",
"download_url": "https://files.pythonhosted.org/packages/38/83/53b59a4c9f6536450e9eb1b78996cb455a7d2de717f340ec3bdf40760487/dictio-0.4.1.tar.gz",
"platform": null,
"description": "[](https://pypi.python.org/pypi/dictIO)\n[](https://pypi.python.org/pypi/dictIO)\n[](https://github.com/dnv-opensource/dictIO/blob/main/LICENSE)\n\n[][dictIO_docs]\n\n# dictIO\ndictIO is a Python package to read, write and manipulate dictionary text files.\n\nIt was designed to leverage the versatility of text based dictionary files, or 'dict files' in short, while easing their use in Python through seamless support for Python dicts.\n\ndictIO supports\n* reading and writing Python dicts in dict files.\n* usage of references and expressions in dict files, dynamically resolved during reading.\n* usage of cascaded dict files, allowing separation of a case-agnostic configuration dict and its case-specific parameterization: baseDict + paramDict = caseDict\n\nFurther, dictIO\n* is widely tolerant in reading different flavours (quotes, preserving comments, etc.)\n* can read and write also JSON, XML and OpenFOAM (with some limitations)\n\n## Installation\n\n```sh\npip install dictIO\n```\n\n## Usage Example\n\ndictIO's core class is `SDict`, a generic data structure for serializable dictionaries. <br>\n`SDict` inherits from Python's builtin `dict`. It can hence be used transparently in any context where a `dict` or any other `MutableMapping` type is expected.\n\nYou can use `SDict` the same way you use `dict`. E.g. you can pass a dict literal to its constructor:\n```py\nfrom dictIO import SDict\n\nmy_dict: SDict[str, int] = SDict(\n {\n \"foo\": 1,\n \"bar\": 2,\n }\n)\n```\n\nThe simplest way to to dump and load a dict to / from a file, is to use SDict's `dump()` and `load()` instance methods:\n\nTo dump `my_dict` to a file, use `.dump()`:\n```py\nmy_dict.dump(\"myDict\")\n```\n\nTo load the formerly dumped file into a new dict, use `.load()`:\n```py\nmy_dict_loaded: SDict[str, int] = SDict().load(\"myDict\")\n```\n\nIn cases where you need more control over how dict files are read and written, <br>\ndictIO's `DictReader` and `DictWriter` classes offer this flexibility, while still maintaining a simple and high level API:\n```py\nfrom dictIO import DictReader, DictWriter\n\nmy_dict = DictReader.read('myDict')\nDictWriter.write(my_dict, 'parsed.myDict')\n```\n\nThe above example reads a dict file, merges any (sub-)dicts included through #include directives, evaluates expressions contained in the dict,\nand finally saves the read and evaluated dict with prefix 'parsed' as 'parsed.myDict'.\n\nThis sequence of reading, evaluating and writing a dict is also called 'parsing' in dictIO.\nBecause this task is so common, dictIO provides a convenience class for it:\nUsing `DictParser.parse()` the above task can be accomplished in one line of code:\n```py\nfrom dictIO import DictParser\n\nDictParser.parse('myDict')\n```\n\nThe `parse` operation can also be executed from the command line, using the 'dictParser' command line script installed with dictIO:\n```sh\ndictParser myDict\n```\n\n_For more examples and usage, please refer to dictIO's [documentation][dictIO_docs]._\n\n\n## File Format\nThe native file format used by dictIO shares, by intention, some commonalities with the [OpenFOAM](https://www.openfoam.com/documentation/guides/latest/doc/openfoam-guide-input-types.html) file format, but is kept simpler and more tolerant to different flavours of string formatting.\n\nWith some limitations, dictIO supports also reading from and writing to [OpenFOAM](https://www.openfoam.com/documentation/guides/latest/doc/openfoam-guide-input-types.html), [Json](https://www.json.org/json-en.html) and [XML](https://www.w3.org/XML/).\n\n_For a detailed documentation of the native file format used by dictIO, see [File Format](fileFormat.rst) in [dictIO's documentation][dictIO_docs] on GitHub Pages._\n\n## Development Setup\n\n### 1. Install uv\nThis project uses `uv` as package manager.\nIf you haven't already, install [uv](https://docs.astral.sh/uv), preferably using it's [\"Standalone installer\"](https://docs.astral.sh/uv/getting-started/installation/#__tabbed_1_2) method: <br>\n..on Windows:\n```sh\npowershell -ExecutionPolicy ByPass -c \"irm https://astral.sh/uv/install.ps1 | iex\"\n```\n..on MacOS and Linux:\n```sh\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n```\n(see [docs.astral.sh/uv](https://docs.astral.sh/uv/getting-started/installation/) for all / alternative installation methods.)\n\nOnce installed, you can update `uv` to its latest version, anytime, by running:\n```sh\nuv self update\n```\n\n### 2. Install Python\nThis project requires Python 3.10 or later. <br>\nIf you don't already have a compatible version installed on your machine, the probably most comfortable way to install Python is through `uv`:\n```sh\nuv python install\n```\nThis will install the latest stable version of Python into the uv Python directory, i.e. as a uv-managed version of Python.\n\nAlternatively, and if you want a standalone version of Python on your machine, you can install Python either via `winget`:\n```sh\nwinget install --id Python.Python\n```\nor you can download and install Python from the [python.org](https://www.python.org/downloads/) website.\n\n### 3. Clone the repository\nClone the dictIO repository into your local development directory:\n```sh\ngit clone https://github.com/dnv-opensource/dictIO path/to/your/dev/dictIO\n```\nChange into the project directory after cloning:\n```sh\ncd dictIO\n```\n\n### 4. Install dependencies\nRun `uv sync` to create a virtual environment and install all project dependencies into it:\n```sh\nuv sync\n```\n> **Note**: Using `--no-dev` will omit installing development dependencies.\n\n> **Note**: `uv` will create a new virtual environment called `.venv` in the project root directory when running\n> `uv sync` the first time. Optionally, you can create your own virtual environment using e.g. `uv venv`, before running\n> `uv sync`.\n\n### 5. (Optional) Activate the virtual environment\nWhen using `uv`, there is in almost all cases no longer a need to manually activate the virtual environment. <br>\n`uv` will find the `.venv` virtual environment in the working directory or any parent directory, and activate it on the fly whenever you run a command via `uv` inside your project folder structure:\n```sh\nuv run <command>\n```\n\nHowever, you still _can_ manually activate the virtual environment if needed.\nWhen developing in an IDE, for instance, this can in some cases be necessary depending on your IDE settings.\nTo manually activate the virtual environment, run one of the \"known\" legacy commands: <br>\n..on Windows:\n```sh\n.venv\\Scripts\\activate.bat\n```\n..on Linux:\n```sh\nsource .venv/bin/activate\n```\n\n### 6. Install pre-commit hooks\nThe `.pre-commit-config.yaml` file in the project root directory contains a configuration for pre-commit hooks.\nTo install the pre-commit hooks defined therein in your local git repository, run:\n```sh\nuv run pre-commit install\n```\n\nAll pre-commit hooks configured in `.pre-commit-config.yaml` will now run each time you commit changes.\n\npre-commit can also manually be invoked, at anytime, using:\n```sh\nuv run pre-commit run --all-files\n```\n\nTo skip the pre-commit validation on commits (e.g. when intentionally committing broken code), run:\n```sh\nuv run git commit -m <MSG> --no-verify\n```\n\nTo update the hooks configured in `.pre-commit-config.yaml` to their newest versions, run:\n```sh\nuv run pre-commit autoupdate\n```\n\n### 7. Test that the installation works\nTo test that the installation works, run pytest in the project root folder:\n```sh\nuv run pytest\n```\n\n## Meta\n\nCopyright (c) 2024 [DNV](https://www.dnv.com) AS. All rights reserved.\n\nFrank Lumpitzsch - [@LinkedIn](https://www.linkedin.com/in/frank-lumpitzsch-23013196/) - frank.lumpitzsch@dnv.com\n\nClaas Rostock - [@LinkedIn](https://www.linkedin.com/in/claasrostock/?locale=en_US) - claas.rostock@dnv.com\n\nSeunghyeon Yoo - [@LinkedIn](https://www.linkedin.com/in/seunghyeon-yoo-3625173b/) - seunghyeon.yoo@dnv.com\n\nDistributed under the MIT license. See [LICENSE](LICENSE.md) for more information.\n\n[https://github.com/dnv-opensource/dictIO](https://github.com/dnv-opensource/dictIO)\n\n## Contributing\n\n1. Fork it (<https://github.com/dnv-opensource/dictIO/fork>)\n2. Create an issue in your GitHub repo\n3. Create your branch based on the issue number and type (`git checkout -b issue-name`)\n4. Evaluate and stage the changes you want to commit (`git add -i`)\n5. Commit your changes (`git commit -am 'place a descriptive commit message here'`)\n6. Push to the branch (`git push origin issue-name`)\n7. Create a new Pull Request in GitHub\n\nFor your contribution, please make sure you follow the [STYLEGUIDE](STYLEGUIDE.md) before creating the Pull Request.\n\n<!-- Markdown link & img dfn's -->\n[dictIO_docs]: https://dnv-opensource.github.io/dictIO/README.html\n[ospx_docs]: https://dnv-opensource.github.io/ospx/README.html\n[farn_docs]: https://dnv-opensource.github.io/farn/README.html\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 [DNV](https://www.dnv.com) [open source](https://github.com/dnv-opensource) 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": "Python package to read, write and manipulate dictionary text files. Supports dictIOs native file format, as well as JSON, XML and OpenFOAM.",
"version": "0.4.1",
"project_urls": {
"Changelog": "https://github.com/dnv-opensource/dictIO/blob/main/CHANGELOG.md",
"Documentation": "https://dnv-opensource.github.io/dictIO/README.html",
"Homepage": "https://github.com/dnv-opensource/dictIO",
"Issues": "https://github.com/dnv-opensource/dictIO/issues",
"Repository": "https://github.com/dnv-opensource/dictIO.git"
},
"split_keywords": [
"dict",
" dictio",
" dictparser"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3a28cbfbd62e313110cd01494d2e63eee2453e6ca53e7eaec5af76e44472848f",
"md5": "128cc7b7429464e6018d300307f0b711",
"sha256": "88dbc6e1474fb547c53e26e7eb56ac8342b35aafabb5083ed1653a1918fe6643"
},
"downloads": -1,
"filename": "dictio-0.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "128cc7b7429464e6018d300307f0b711",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.14,>=3.10",
"size": 59716,
"upload_time": "2025-01-18T13:56:26",
"upload_time_iso_8601": "2025-01-18T13:56:26.890821Z",
"url": "https://files.pythonhosted.org/packages/3a/28/cbfbd62e313110cd01494d2e63eee2453e6ca53e7eaec5af76e44472848f/dictio-0.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "388353b59a4c9f6536450e9eb1b78996cb455a7d2de717f340ec3bdf40760487",
"md5": "df1ccdf9ca368d472f7922158c0c0b07",
"sha256": "f1f50eae9fcd47fc2bd3d1510ed5ac6dd5b851062e1a06e70fa1bf72c04c85f0"
},
"downloads": -1,
"filename": "dictio-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "df1ccdf9ca368d472f7922158c0c0b07",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.14,>=3.10",
"size": 96767,
"upload_time": "2025-01-18T13:56:28",
"upload_time_iso_8601": "2025-01-18T13:56:28.616536Z",
"url": "https://files.pythonhosted.org/packages/38/83/53b59a4c9f6536450e9eb1b78996cb455a7d2de717f340ec3bdf40760487/dictio-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-18 13:56:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dnv-opensource",
"github_project": "dictIO",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "dictio"
}