from typing import OrderedDict


def sort_OD(od):
    """ Sort an OrderedDict by key recursively"""
    out = OrderedDict()
    for key, val in sorted(od.items()):
        if isinstance(val, dict):
            out[key] = sort_OD(val)
        else:
            out[key] = val
    return out