class MyInterpreter(cmd.Cmd):

    def do_level1(self, args):
        pass

def do_level2_subcommand_1(self, args):
    pass

def do_level2_subcommand_2(self, args):
    pass

def do_level3_subcommand_1(self, args):
    pass
MyInterpreter().cmdloop()
How to do a multi-level CLI in Python?