Dave Cinege Git Repo thesaurus / 6696f50 README.rst

Tree @6696f50 (Download .tar.gz)

README.rst @6696f50view markup · raw · history · blame

Python Thesaurus and ThesaurusCfg

Copyright (c) 2012-2019 Dave Cinege. All rights reserved.

See the end of this file for further copyright and license information

Quick look

from thesaurus import thes, Keypath
t = thes()
t.set_path('a.b.c.d', 'Hello')
print(t['a']['b']['c']['d'])        # as nested items
print(t.a.b.c.d)                    # as attributes
print(t.a.b['c'].d)                 # as both
kp = Keypath('a.b.c.d')
print(t[kp])                        # as a keypath

>>> 'a.b.c.d' in t
>>> kp[:-2] in t
>>> print(kp)
>>> print(repr(kp))
['a', 'b', 'c', 'd']

cfgs = '''
prog.version(static_int)    = 123
opt.verbose (str_to_bool)   = yes
hi                          = Hello
from thesauruscfg import thescfg
cfg = thescfg()
>>> cfg.parse(cfgs)
{'prog': {'version': 123}, 'opt': {'verbose': True}, 'hi': 'Hello'}

import json
>>> print(json.dumps(cfg, indent=4, separators=(',', ': ')))
    "prog": {
        "version": 123
    "opt": {
        "verbose": true
    "hi": "Hello"

Quick start

$ python thesauruscfg_sample.py

Then review thesauruscfg_sample.py and thesauruscfg_sample.cfg and you will get an idea what Thesaurus and ThesaurusCfg are all about.

General Information

Source code:https://git.cinege.com//thesaurus
Telegram Group:https://t.me/PythonThesaurus

At the momement there is no email list, wiki, etc.


Thesaurus is a mapping data type with key recursion and attribute aliasing. It is a subclass of dict() and compatible as a dictionary replacement baring where key path recursion may take place.

Thesaurus prefers to be imported and called as thes() in the same way you would use dict(). Thesaurus likes to think of itself as a Python data type primative that should be used along side of dict(), similar to the relationship between list() and tuple(); they are overlappingly similar but serve different purposes and diverge to incompatibilities. Thesaurus is currently content with not having it's own data type tokens. Hopefully so are you.

ThesaurusExtended is a subclass of Thesaurus providing additional usablity methods.

ThesaurusCfg is a subclass of ThesaurusExtended providing a configuration file parser and per key data coercion methods.

The Thesaurus family works with Python 2.6+ to 3.8+.

Currect State of Code - 2019-11-13

Thesaurus first came about in December 2012. It has gone through a total of maybe 6 complete re-writes. In mid 2019 I think I finally got it right with the implemintation of Keypath's and also the creation of ThesaurusCfg, something I've been wishing I've had to use for myself for at least the last 4 years.

The current version you will find here has recently had the recent addition of Keypaths and while it is quite usable might still have a few bugs to iron out.

Additonally parts should be cleaned and reimplemented now that Keypath's have been implemented. If you are reviewing the code, this will likely stand out. With that said, please remember that at this stage few things have been done by accident. There are certainly section that can be cleaned for readablity, however they are this way, on purpose, for performance.

ThesaurusCfg is quite new. It works. I have a version of it frozen in production code. But it's not had the maturity of Thesaurus in practise and requires a more thorough re-write.

I'm putting this code out now to gain feedback to finalize for a proper release. As such, both modules are very subject to change at this time. Specifically I have the following decisions to make:

  • Finalize name conventions. Use set_path() or setpath()?

  • Finalize specialtiy method names, Are merge(), mesh() and screen() good names that make sense? I am struggling with the ThesaurusExtended method names myself.

  • Review how I do recursive copy/deepcopys.

  • Decide how to properly handle copying ThesaurusCfg coercion methods.

  • Resolve Thesaurus's schizophrenia.

    v = t['a.b.c']            # This recurses
    t['a.b.c'] = v            # This does not, needs set_path().

    I want to be comfortable this feels natural to others or make changes.