Bystroushaak's blog / English section / Programming / Tools I use / Tools I use: argparse builder

Tools I use: argparse builder

argparse builder is one of my older projects I created in 2014 when I found out that Brython (browser python) exists. It is a simple graphical interface for quick creation of the argparse commandline switches for your scripts.

I created it, because I was constantly forgetting types of parameters for the argparse and what options there are.

Here is how it looks like:

You can type your arguments into the table presented in the Arguments section.

If you are not sure what the argument syntax is, you can click on the link next to it and popup with documentation will open:

Adding new arguments is easy:

Here I highlighted some key elements of the argument table. Notice that there are quotes around some of the arguments. That means, that they will be wrapped with quotes in the output. Notice That nargs don't have quotes, so I have to insert them manually. That is because sometimes you want to use something like argparse.REMAINDER or some other variables.

You can also choose actions and it changes some of the properties in the table. For example, I want the second argument to be binary, so I choose store_true from the dropdown menu.

When I want the generated code, I simply click into the output:

And here it is:

When I copy the code to the python file, I can see how it works:

$ ./ -h
usage: [-h] [-f [FILE [FILE ...]]] [-s]

optional arguments:
  -h, --help            show this help message and exit
  -f [FILE [FILE ...]], --file [FILE [FILE ...]]
                        List of input files.
  -s, --something       Some binary switch.


Although the code is old and unmaintained for long time (last commit 2016), it still works as expected and I use it every time I need to add some argparse interface. It massively lowers the cognitive load, so I don't have to remember all kind argument types and parameters. And it works fine for python3, although it was meant for 2.7.

I highly suggest remembering the keywords "argparse builder" and just google it next time you need to add argparse interface to your script, it should be first result in google.


Relevant discussion

Become a Patron