arg_count = foo.__code__.co_argcount
args = foo.__code__.co_varnames[:arg_count]
args_dict = {}
for k, v in d.items():
    if k in args:
        args_dict[k] = v
foo(**args_dict)
Unpacking keyword arguments, but only the ones that match the function