title: Python convert dictionary to argparse
body: <p>Right now, I have a script that can accept command line arguments using argparse. For example, like this:</p>
  <pre class="lang-py prettyprint-override"><code>#foo.py
  def function_with_args(optional_args=None):
    parser = argparse.ArgumentParser()
    # add some arguments
    args = parser.parse_args(optional_args)
    # do something with args
  </code></pre>
  <p>However, I'd like to be able to use this function with a dictionary instead, for example with something like this:</p>
  <pre class="lang-py prettyprint-override"><code>def function_using_dict(**kwargs):
    # define parser and add some arguments
    args = parser.parse_dict_args(kwargs)
    # everything else is the same
  </code></pre>
  <p>Note that I have a lot of arguments with default values in argparse which I'd like to use, so the following wouldn't work:</p>
  <pre><code>def function_no_default_args(**kwargs):
    args = kwargs # not using default values that we add to the parser!
  </code></pre>