title: How to call a python command line tool from a web service when API endpoint is hit?
body: <p>I have a working command line tool that does a thing well written in Python. It takes a few parameters from the command line using the Argparse package.</p>
  
  <p>Now we have a small web service with a nice endpoint to hit to trigger this command line tool. So now the JSON payload has to contain the former-command-line parameters. </p>
  
  <p>How do I pass the JSON payload to the python script without jumping into my OS environment and calling a bash command or something like that? Is there a way to do this with minimal changes to the CLI python script? In case we want to keep the CLI functionality for local executions?</p>
  
  <p>I'm just not sure on the proper way to do this. Thanks</p>
  
  <p>Here's the code "template" if that helps:</p>
  
  <pre class="lang-py prettyprint-override"><code>arser = argparse.ArgumentParser(...)
  parser.add_argument("arg1", ...)
  args = parser.parse_args()
  
  actual_param = args.arg1
  .
  .
  .
  def main_logic_flow(parameter):
      ....
  
  if __name__ == "__main__":
      main_logic_flow(actual_param)
  </code></pre>