Package: dict-toolbox
INSTALLATIONpipinstalldict-toolboxContains various dict tools from theSalt Project.Differfromdict_toolsimportdifferdeep_diffComputes the difference between to dictionaries.recursive_diffComputes the recursive difference between two dictionaries.Trimfromdict_toolsimporttrimtrim_dictTakes a dictionary and iterates over its keys, looking for
large values and replacing them with a trimmed string.Updatefromdict_toolsimporttrimupdateMerges “upd” recursively into the targetmerge_listmerge_recursemerge_aggregatemerge_overwritemergeensure_dict_keyEnsures that in_dict contains the series of recursive keys defined in keys.set_dict_key_valueEnsures that in_dict contains the series of recursive keys defined in keys.
Also sets whatever is at the end ofin_dicttraversed withkeystovalue.update_dict_key_valueEnsures that in_dict contains the series of recursive keys defined in keys.
Also updates the dict, that is at the end ofin_dicttraversed withkeys,
withvalue.append_dict_key_valueEnsures that in_dict contains the series of recursive keys defined in keys.
Also appendsvalueto the list that is at the end ofin_dicttraversed
withkeys.extend_dict_key_valueEnsures that in_dict contains the series of recursive keys defined in keys.
Also extends the list, that is at the end ofin_dicttraversed withkeys,
withvalue.XMLfromdict_toolsimportxmlto_dictConvert an XML tree into a dict. The tree that is passed in must be an
ElementTree object.YAMLEXfromdict_toolsimportyamlexYAMLEX is a format that allows for things like sls files to be
more intuitive.SLSMapEnsures that dict str() and repr() are YAML friendly.SLSStringEnsures that str str() and repr() are YAML friendly.AggregatedMapAggregatedSequenceDumpersls dumper.merge_recursiveMerge obj_b into obj_a.MySQLfromdict_toolsimportmysqlto_numConvert a string to a number.to_dictConvert MySQL-style output to a python dictionary.DATAfromdict_toolsimportdataCaseInsensitiveDictInspired by requests’ case-insensitive dict implementation, but works with
non-string keys as well.ImmutableDictAn immutable mapping that can access it’s keys via the namespaceNamespaceDictA dictionary that can access it’s string keys through the namespacecompare_dictsCompare before and after results from various functions, returning a
dict describing the chagnes that were made.is_dictlistReturns True if data is a list of one-element dicts (as found in many SLS schemas)object_to_dictConvert an arbitrary object to a dictionaryrecursive_diffPerforms a recursive diff on mappings and/or iterables and returns the result
in a {‘old’: values, ‘new’: values}-style.
Compares dicts and sets unordered (obviously), OrderedDicts and Lists ordered
(but only if botholdandneware of the same type),
all other Mapping types unordered, and all other iterables ordered.repack_dictlistTakes a list of one-element dicts (as found in many SLS schemas) and
repacks into a single dictionary.subdict_matchCheck for a match in a dictionary using a delimiter character to denote
levels of subdicts, and also allowing the delimiter character to be
matched. Thus, ‘foo:bar:baz’ will match data[‘foo’] == ‘bar:baz’ and
data[‘foo’][‘bar’] == ‘baz’. The latter would take priority over the
former, as more deeply-nested matches are tried first.traverse_dictTraverse a dict using a colon-delimited (or otherwise delimited, using the
‘delimiter’ param) target string. The target ‘foo:bar:baz’ will return
data[‘foo’][‘bar’][‘baz’] if this value exists, and will otherwise return
the dict in the default argument.traverse_dict_and_listTraverse a dict or list using a colon-delimited (or otherwise delimited,
using the ‘delimiter’ param) target string. The target ‘foo:bar:0’ will
return data[‘foo’][‘bar’][0] if this value exists, and will otherwise
return the dict in the default argument.
Function will automatically determine the target type.
The target ‘foo:bar:0’ will return data[‘foo’][‘bar’][0] if data like
{‘foo’:{‘bar’:[‘baz’]}} , if data like {‘foo’:{‘bar’:{‘0’:’baz’}}}
then return data[‘foo’][‘bar’][‘0’]Argfromdict_toolsimportargyamlify_argyaml.safe_load the argAggregationfromdict_toolsimportaggregationMakes it possible to introspect dataset and aggregate nodes
when it is instructedleveliseDescribe which levels are allowed to do deep merging.markConvert obj into an Aggregate instanceaggregateMerge obj_b into obj_a.