def topological_sort(graph):
    """Topological sort algorithm to return a list of keys to a dictionary
    of lists of dependencies. The returned keys define an order so
    that all dependent items are in front of the originating item.

    """

    def recurse(node, path):
        if node not in path:
            edges = graph[node]

            for edge in edges:
                if edge not in path:
                    path = recurse(edge, path)

            path = path + [node]

        return path

    path = []

    for node in sorted(graph):
        path = recurse(node, path)

    return path