If creating another process is unnecessary, then exposing a function that you call from the Flask app is the right idea. Have it take as an argument the list of string arguments that you then pass to the parser. Presumably, you're using
argparse.ArgumentParser
, whose parse_args
method does let you do that (see the docs). So, in the script, you'd just pass sys.argv
to that function and in your Flask app, yeah, you'd just pass a list of strings containing the values you wanted. It's just good old dependency injection.