Today I learned about Fire AND Gooey
Sometimes I get bogged down in writing proper argparse when it really is not needed.
Are there any edge cases where Fire does not work too well, like some strange parameters (for example tuple as dictionary key)?
So we have one file which contains the class with all the functions we want to expose (in our case, the class is named JobManager). At the end, it goes
if __name__ == '__main__':
fire.Fire(JobManager)
which takes care of all the CLI access we could want.Then we have a second file for the GUI, which has a main-function that does some argparse stuff. The GUI interface is simplified from the CLI interface, so it's not that much work to write the argparse code for that. Simplified, it looks a little like this :
@Gooey(default_size=(1000, 600))
def main():
parser = GooeyParser(description="jobGUI")
# argparser code
args = parser.parse_args()
JobManager(args.name, args.whatever)
if __name__ == '__main__':
main() if __name__ == '__main__':
fire.Fire(JobManager)
which turns it into an instant CLI.Then we have a separate gui.py file, which contains the Gooey code. This includes the class mentioned above, and builds a minimalistic GUI around it. This does need some argparse-based code, but in the GUI we only expose a small subset of the full power, so we only need a little bit of argparse-code.
P.S. I'm not certain this is the best way to approach things, but it's the way we use it, and we're happy with it so far.
We use it in combination with Python Fire [0] to easily convert python code to something that users can interact with. Python fire converts our python code into a CLI without all the manual parameter parsing, and Gooey turns the CLI into a simple GUI.
[0] https://github.com/google/python-fire