def attr(obj, *path, **kwargs):
    """Safely get a nested attribute from an dictionary"""
    default = kwargs.get('default')
    if obj is None:
        return default
    res = obj
    for p in path:
        if p not in res:
            return default
        res = res[p]
    return res
