import collections def dict_merge(dct, merge_dct): for k, v in merge_dct.items(): if (k in dct and isinstance(dct[k], dict) and isinstance(merge_dct[k], dict)): #noqa dict_merge(dct[k], merge_dct[k]) else: dct[k] = merge_dct[k]