1============ 2DICT-TOOLBOX 3============ 4 5INSTALLATION 6============ 7.. code-block:: bash 8 9 pip install dict-toolbox 10 11Contains various dict tools from the `Salt Project <https://github.com/saltstack/salt>`_. 12 13Differ 14====== 15.. code-block:: python 16 17 from dict_tools import differ 18 19deep_diff 20--------- 21Computes the difference between to dictionaries. 22 23recursive_diff 24-------------- 25Computes the recursive difference between two dictionaries. 26 27Trim 28==== 29.. code-block:: python 30 31 from dict_tools import trim 32 33trim_dict 34--------- 35Takes a dictionary and iterates over its keys, looking for 36large values and replacing them with a trimmed string. 37 38 39Update 40====== 41.. code-block:: python 42 43 from dict_tools import trim 44 45 46update 47------ 48Merges "upd" recursively into the target 49 50merge_list 51---------- 52 53merge_recurse 54------------- 55 56merge_aggregate 57--------------- 58 59merge_overwrite 60--------------- 61 62merge 63----- 64 65ensure_dict_key 66--------------- 67Ensures that in_dict contains the series of recursive keys defined in keys. 68 69set_dict_key_value 70------------------ 71Ensures that in_dict contains the series of recursive keys defined in keys. 72Also sets whatever is at the end of `in_dict` traversed with `keys` to `value`. 73 74update_dict_key_value 75--------------------- 76Ensures that in_dict contains the series of recursive keys defined in keys. 77Also updates the dict, that is at the end of `in_dict` traversed with `keys`, 78with `value`. 79 80append_dict_key_value 81--------------------- 82Ensures that in_dict contains the series of recursive keys defined in keys. 83Also appends `value` to the list that is at the end of `in_dict` traversed 84with `keys`. 85 86extend_dict_key_value 87--------------------- 88Ensures that in_dict contains the series of recursive keys defined in keys. 89Also extends the list, that is at the end of `in_dict` traversed with `keys`, 90with `value`. 91 92 93XML 94=== 95.. code-block:: python 96 97 from dict_tools import xml 98 99to_dict 100------- 101Convert an XML tree into a dict. The tree that is passed in must be an 102ElementTree object. 103 104YAMLEX 105====== 106.. code-block:: python 107 108 from dict_tools import yamlex 109 110YAMLEX is a format that allows for things like sls files to be 111more intuitive. 112 113SLSMap 114------ 115Ensures that dict str() and repr() are YAML friendly. 116 117SLSString 118--------- 119Ensures that str str() and repr() are YAML friendly. 120 121AggregatedMap 122------------- 123 124AggregatedSequence 125------------------ 126 127Dumper 128------ 129sls dumper. 130 131merge_recursive 132--------------- 133Merge obj_b into obj_a. 134 135MySQL 136===== 137.. code-block:: python 138 139 from dict_tools import mysql 140 141to_num 142------ 143Convert a string to a number. 144 145 146to_dict 147------- 148Convert MySQL-style output to a python dictionary. 149 150 151DATA 152==== 153.. code-block:: python 154 155 from dict_tools import data 156 157CaseInsensitiveDict 158------------------- 159Inspired by requests' case-insensitive dict implementation, but works with 160non-string keys as well. 161 162ImmutableDict 163------------- 164An immutable mapping that can access it's keys via the namespace 165 166NamespaceDict 167------------- 168A dictionary that can access it's string keys through the namespace 169 170 171compare_dicts 172------------- 173Compare before and after results from various functions, returning a 174dict describing the chagnes that were made. 175 176is_dictlist 177----------- 178Returns True if data is a list of one-element dicts (as found in many SLS schemas) 179 180object_to_dict 181-------------- 182Convert an arbitrary object to a dictionary 183 184recursive_diff 185-------------- 186Performs a recursive diff on mappings and/or iterables and returns the result 187in a {'old': values, 'new': values}-style. 188Compares dicts and sets unordered (obviously), OrderedDicts and Lists ordered 189(but only if both ``old`` and ``new`` are of the same type), 190all other Mapping types unordered, and all other iterables ordered. 191 192repack_dictlist 193--------------- 194Takes a list of one-element dicts (as found in many SLS schemas) and 195repacks into a single dictionary. 196 197subdict_match 198------------- 199Check for a match in a dictionary using a delimiter character to denote 200levels of subdicts, and also allowing the delimiter character to be 201matched. Thus, 'foo:bar:baz' will match data['foo'] == 'bar:baz' and 202data['foo']['bar'] == 'baz'. The latter would take priority over the 203former, as more deeply-nested matches are tried first. 204 205 206traverse_dict 207------------- 208Traverse a dict using a colon-delimited (or otherwise delimited, using the 209'delimiter' param) target string. The target 'foo:bar:baz' will return 210data['foo']['bar']['baz'] if this value exists, and will otherwise return 211the dict in the default argument. 212 213traverse_dict_and_list 214---------------------- 215Traverse a dict or list using a colon-delimited (or otherwise delimited, 216using the 'delimiter' param) target string. The target 'foo:bar:0' will 217return data['foo']['bar'][0] if this value exists, and will otherwise 218return the dict in the default argument. 219Function will automatically determine the target type. 220The target 'foo:bar:0' will return data['foo']['bar'][0] if data like 221{'foo':{'bar':['baz']}} , if data like {'foo':{'bar':{'0':'baz'}}} 222then return data['foo']['bar']['0'] 223 224Arg 225=== 226.. code-block:: python 227 228 from dict_tools import arg 229 230yamlify_arg 231----------- 232yaml.safe_load the arg 233 234 235Aggregation 236=========== 237.. code-block:: python 238 239 from dict_tools import aggregation 240 241Makes it possible to introspect dataset and aggregate nodes 242when it is instructed 243 244 245levelise 246-------- 247Describe which levels are allowed to do deep merging. 248 249mark 250---- 251Convert obj into an Aggregate instance 252 253aggregate 254--------- 255Merge obj_b into obj_a. 256