class MyArgumentParser(argparse.ArgumentParser):

    def parse_subargs(self, *args, **kw):
        args = argparse.ArgumentParser.parse_args(self, *args, **kw)
topdest = [action.dest for action in parser._actions]
subargs = {}
for key, value in list(args.__dict__.items()):
    if key not in topdest:
        delattr(args, key)
subargs[key] = value
return args, subargs
How to have sub-parser arguments in separate namespace with argparse?