def ctx_get(ctx, key, default=None):
    """Iterate up context tree and return the value at `key` if found"""
    while not getattr(ctx, 'is_root', False):
        value = getattr(ctx, key, None)
        if value is not None:
            return value
        ctx = ctx.parent
    return default
