from typing import OrderedDict


def sortdict(items):
    """Recursively sort a dictionary by keys."""
    ordered = OrderedDict()
    for key in sorted(items.keys()):
        value = items[key]
        if isinstance(value, dict):
            value = sortdict(value)
        ordered[key] = value
    return ordered