[Python-ideas] argparse - add support for environment variables (a proposal)
ndbecker2 at gmail.com
Wed Mar 27 16:47:45 CET 2013
Here's an idea. We have 4 main sources of config:
1. app defaults
2. config file
3. env var
4. command line
Instead of adding anything to the code for each of these parsers, suppose that
each of them accepted a dictionary of options in a common form, so that they
could be composed easily.
For example, suppose we call config file parser 1st, and it returns a dict of
what items are
set in the config file (not the defaults). Then argparse is called (without
using and defaults), passing it that dictionary, which it can add to or overide.
Finally, options not in the dict get defaults applied.
Having not dug into technical details, I'm imagining that either arparse already
can accept a dict or options, or could be easily modified to. Or, we simply call
argparse normally, then take it's dict and we merge the dicts outside of
More information about the Python-ideas