title: Python: Argument Parsing Validation Best Practices
body: <p>Is it possible when using the argparse module to add validation when parsing arguments?</p>
  
  <pre><code>from argparse import ArgumentParser
  
  parser = ArgumentParser(description='Argument parser for PG restore')
  
  parser.add_argument('--database', dest='database',
                      default=None, required=False, help='Database to restore')
  
  parser.add_argument('--backup', dest='backup',
                      required=True, help='Location of the backup file')
  
  parsed_args = parser.parse_args()
  </code></pre>
  
  <p>Would it be possible, to add a validation check to this argument parser, to make sure the backup file / database exist? Rather than having to add an extra check after this for every parameter such as:</p>
  
  <pre><code>from os.path import exists
  if not database_exists(parsed_args.database):
      raise DatabaseNotFoundError
  if not exists(parsed_args.backup):
      raise FileNotFoundError
  </code></pre>