dictio

Python package to read, write and manipulate dictionary text files. Supports dictIOs native file format, as well as JSON, XML and OpenFOAM.

https://github.com/dnv-opensource/dictio

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.0%) to scientific vocabulary
Last synced: 7 months ago · JSON representation ·

Repository

Python package to read, write and manipulate dictionary text files. Supports dictIOs native file format, as well as JSON, XML and OpenFOAM.

Basic Info
Statistics
  • Stars: 3
  • Watchers: 6
  • Forks: 1
  • Open Issues: 0
  • Releases: 30
Created over 4 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog License Citation

README.md

pypi versions license ci 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.
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,
dictIO's DictReader and DictWriter classes offer this flexibility, while still maintaining a simple and high level API: ```py from dictIO import DictReader, DictWriter

mydict = DictReader.read('myDict') DictWriter.write(mydict, '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.

File Format

The native file format used by dictIO shares, by intention, some commonalities with the OpenFOAM 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, Json and XML.

For a detailed documentation of the native file format used by dictIO, see File Format in dictIO's documentation on GitHub Pages.

Development Setup

1. Install uv

This project uses uv as package manager. If you haven't already, install uv, preferably using it's "Standalone installer" method:
..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 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.
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 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.
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:
..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 AS. All rights reserved.

Frank Lumpitzsch - @LinkedIn - frank.lumpitzsch@dnv.com

Claas Rostock - @LinkedIn - claas.rostock@dnv.com

Seunghyeon Yoo - @LinkedIn - seunghyeon.yoo@dnv.com

Distributed under the MIT license. See LICENSE for more information.

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 before creating the Pull Request.

Owner

  • Name: DNV open source
  • Login: dnv-opensource
  • Kind: organization
  • Location: Norway

Open source from DNV

Citation (CITATION.cff)

title: dictIO
version: 0.4.1
abstract: >-
  Python package to read, write and manipulate dictionary text files.
  Supports dictIOs native file format, as well as JSON, XML and OpenFOAM.
type: software
authors:
  - name: DNV SE
    address: 'Brooktorkai 18'
    post-code: '20457'
    city: Hamburg
    country: DE
    website: 'https://www.dnv.com/'
  - given-names: Frank
    family-names: Lumpitzsch
    affiliation: DNV
    email: frank.lumpitzsch@dnv.com
    website: 'https://www.linkedin.com/in/frank-lumpitzsch-23013196/'
  - given-names: Claas
    family-names: Rostock
    affiliation: DNV
    email: claas.rostock@dnv.com
    website: 'https://www.linkedin.com/in/claasrostock/?locale=en_US'
  - given-names: Seunghyeon
    family-names: Yoo
    affiliation: DNV
    email: seunghyeon.yoo@dnv.com
    website: 'https://www.linkedin.com/in/seunghyeon-yoo-3625173b/'
keywords:
license: MIT
license-url: 'https://dnv-opensource.github.io/dictIO/LICENSE.html'
url: 'https://dnv-opensource.github.io/dictIO/README.html'
repository-code: 'https://github.com/dnv-opensource/dictIO'
message: 'Please cite this software using these metadata.'
cff-version: 1.2.0

GitHub Events

Total
  • Create event: 14
  • Issues event: 2
  • Release event: 6
  • Delete event: 9
  • Issue comment event: 3
  • Push event: 367
  • Pull request review event: 1
  • Pull request event: 18
Last Year
  • Create event: 14
  • Issues event: 2
  • Release event: 6
  • Delete event: 9
  • Issue comment event: 3
  • Push event: 367
  • Pull request review event: 1
  • Pull request event: 18

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 6
  • Total pull requests: 33
  • Average time to close issues: 3 months
  • Average time to close pull requests: 3 days
  • Total issue authors: 2
  • Total pull request authors: 2
  • Average comments per issue: 0.33
  • Average comments per pull request: 0.21
  • Merged pull requests: 31
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 11
  • Average time to close issues: 1 day
  • Average time to close pull requests: 3 days
  • Issue authors: 1
  • Pull request authors: 2
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.27
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • ClaasRostock (4)
  • frl000 (1)
Pull Request Authors
  • ClaasRostock (44)
  • frl000 (5)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 14,969 last-month
  • Total dependent packages: 2
  • Total dependent repositories: 1
  • Total versions: 31
  • Total maintainers: 2
pypi.org: dictio

Python package to read, write and manipulate dictionary text files. Supports dictIOs native file format, as well as JSON, XML and OpenFOAM.

  • Homepage: https://github.com/dnv-opensource/dictIO
  • Documentation: https://dnv-opensource.github.io/dictIO/README.html
  • 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.
  • Latest release: 0.4.1
    published about 1 year ago
  • Versions: 31
  • Dependent Packages: 2
  • Dependent Repositories: 1
  • Downloads: 14,969 Last month
Rankings
Dependent packages count: 3.2%
Downloads: 11.1%
Average: 18.7%
Dependent repos count: 21.5%
Stargazers count: 27.8%
Forks count: 29.8%
Maintainers (2)
Last synced: 7 months ago

Dependencies

requirements.txt pypi
  • Sphinx >=4.3.0
  • flake8 >=4.0.1
  • furo *
  • jsonschema >=4.2.1
  • lxml >=4.6.4
  • myst-parser >=0.15.2
  • pep8-naming >=0.12.1
  • pytest >=6.2.5
  • pytest-cov >=3.0.0
  • pytest-randomly >=3.11.0
  • sphinx-argparse-cli >=1.8.2
  • yapf >=0.31.0
requirements-dev.txt pypi
  • Sphinx >=5.3 development
  • black >=23.1.0 development
  • furo >=2022.9.29 development
  • myst-parser >=0.18 development
  • pyright >=1.1.292 development
  • pytest >=7.2 development
  • pytest-cov >=4.0 development
  • pytest-randomly >=3.12 development
  • ruff >=0.0.240 development
  • sourcery >=1.0.3 development
  • sourcery-cli >=1.0.3 development
  • sphinx-argparse-cli >=1.10 development
.github/workflows/_build_and_publish_documentation.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • ammaraskar/sphinx-problem-matcher master composite
  • peaceiris/actions-gh-pages v3 composite
.github/workflows/_build_package.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
.github/workflows/_code_quality.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v4 composite
  • psf/black stable composite
.github/workflows/_merge_into_release.yml actions
  • actions/checkout v3 composite
  • devmasx/merge-branch v1.4.0 composite
.github/workflows/_publish_package.yml actions
  • actions/download-artifact v3 composite
  • pypa/gh-action-pypi-publish v1.5.2 composite
.github/workflows/_test.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v4 composite
.github/workflows/_test_future.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v4 composite
.github/workflows/nightly_build.yml actions
.github/workflows/publish_release.yml actions
.github/workflows/pull_request_to_main.yml actions
.github/workflows/push.yml actions
.github/workflows/push_to_main.yml actions
.github/workflows/push_to_release.yml actions
pyproject.toml pypi
requirements-types.txt pypi
  • types-lxml >=2023.3.28