def key_by(items, key, children_key=False):
    """
    Index a list of dicts by the value of given key - forced to lowercase.
    Set child_key to say 'children' to recurse down a tree with 'children' attributes on nodes.
    """
    index = {}

    def inner(items, parent_key=None):
        for item in items:
            if parent_key:
                item["parent_key"] = parent_key
            _item_key = item[key] if isinstance(item[key], int) else item[key].lower()
            index[_item_key] = item
            if item.get(children_key):
                inner(item[children_key], _item_key)

    inner(items)
    return index