Package: dictIO
dictIOdictIO 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 supportsreading 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 = caseDictFurther, dictIOis widely tolerant in reading different flavours (quotes, preserving comments, etc.)can read and write also JSON, XML and OpenFOAM (with some limitations)InstallationpipinstalldictIOUsage ExampledictIO provides a simple, high level API that allows reading and writing Python dicts from/to dict files:fromdictIOimportDictReader,DictWritermy_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:fromdictIOimportDictParserDictParser.parse('myDict')The above task can also be invoked from the command line, using the 'dictParser' command line script installed with dictIO:dictParsermyDictFor more examples and usage, please refer to dictIO'sdocumentation.File FormatThe default dictionary file format used by dictIO shares, by intention, some commonalities with theOpenFOAMfile format, but is kept simpler and more tolerant to different flavours of string formatting.With some limitations, dictIO supports also reading from and writing toOpenFOAM,JsonandXML.For a detailed documentation of the dict file format used by dictIO, seeFile FormatindictIO's documentationon GitHub Pages.Development SetupInstall Python 3.9 or higher, i.e.Python 3.10orPython 3.11Update pip and setuptools:python-mpipinstall--upgradepipsetuptoolsgit clone the dictIO repository into your local development directory:gitclonehttps://github.com/dnv-opensource/dictIOpath/to/your/dev/dictIOIn the dictIO root folder:Create a Python virtual environment:python-mvenv.venvActivate the virtual environment:..on Windows:>.venv\Scripts\activate.bat..on Linux:source.venv/bin/activateUpdate pip and setuptools:(.venv)$python-mpipinstall--upgradepipsetuptoolsInstall dictIO's dependencies:(.venv)$pipinstall-rrequirements-dev.txtThis should return without errors.Finally, install dictIO itself, yet not as a regular package but as aneditablepackage instead, using the pip install option -e:(.venv)$pipinstall-e.Test that the installation works (in the dictIO root folder):(.venv)$pytest.MetaCopyright (c) 2024DNVopen sourceFrank Lumpitzsch –@LinkedIn–frank.lumpitzsch@dnv.comClaas Rostock –@LinkedIn–claas.rostock@dnv.comSeunghyeon Yoo –@LinkedIn–seunghyeon.yoo@dnv.comDistributed under the MIT license. SeeLICENSEfor more information.https://github.com/dnv-opensource/dictIOContributingFork it (https://github.com/dnv-opensource/dictIO/fork)Create your branch (git checkout -b myBranchName)Commit your changes (e.g.git commit -m 'place a descriptive commit message here')Push to the branch (e.g.git push origin myBranchName)Create a new Pull Request in GitHubFor your contribution, please make sure you follow theSTYLEGUIDEbefore creating the Pull Request.