Skip to main content

A collection of argparse extensions

Project description


I was having shower and this name came up.

At the moment this is a collection of argparse extensions I have written and found useful in recent times.


  • @arg_converter decorator to write simple argument value parsers without the argparse.Action boilerplate
  • @subcommand decorator to save you from all the add_subparsers and set_defaults(func=).
  • @cli decorator to generate a command-line interface.


The example below combines all the features, but the tool doesn’t enforce it on you.

If you have an existing argparse.ArgumentParser definition, you should be able to replace it with aarghparse by just changing the initialisation line to parser = aarghparse.ArgumentParser(...).

import datetime as dt


from aarghparse import ArgumentParser, arg_converter, cli

def calendar_cli(parser: ArgumentParser, subcommand: ArgumentParser.subcommand):
    Command-line calendar.


    def tz_arg(value):

            ["--tz", {
                "action": tz_arg,
                "help": "Timezone",
    def now_cmd(args):
        Prints today's date.
        date_format = args.date_format or "%Y-%m-%d %H:%M:%S"

if __name__ == "__main__":

If you install python-dateutil then you can try the above with:

python -m aarghparse.examples.calendar --help
python -m aarghparse.examples.calendar now --help
python -m aarghparse.examples.calendar now --tz "Europe/Riga"
python -m aarghparse.examples.calendar --date-format "%d.%m.%Y." now --tz "Europe/Riga"

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aarghparse, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size aarghparse-0.2.0-py3-none-any.whl (5.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aarghparse-0.2.0.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page