My 2 cents: for my own purposes I developed minydra
, a simple command-line parser which includes a custom class MinyDict
(inspired by addict
):
In [1]: from minydra import MinyDictIn [2]: args = MinyDict({"foo": "bar", "yes.no.maybe": "idontknow"}).pretty_print(); args╭──────────────────────────────╮│ foo : bar ││ yes.no.maybe : idontknow │╰──────────────────────────────╯Out[2]: {'foo': 'bar', 'yes.no.maybe': 'idontknow'}In [3]: args.resolve().pretty_print(); args╭──────────────────────────╮│ foo : bar ││ yes │││no ││││maybe : idontknow │╰──────────────────────────╯Out[3]: {'foo': 'bar', 'yes': {'no': {'maybe': 'idontknow'}}}In [4]: args.yes.no.maybeOut[4]: "idontknow"In [5]: "foo" in argsOut[5]: TrueIn [6]: "rick" in argsOut[6]: FalseIn [7]: args.morty is NoneOut[7]: TrueIn [8]: args.items()Out[8]: dict_items([('foo', 'bar'), ('yes', {'no': {'maybe': 'idontknow'}})])
It goes further than addict
by adding dumping/loading methods to/from json
yaml
and pickle
and also has a strict
mode in MinyDict.update()
to prevent the creation of new keys (this is useful to prevent typos in the command-line)