IT lexicon › Programming › argparse

argparse

Programming På svenska → Updated: 2026-07-30

Python's built-in module for command line arguments — declare the flags and get parsing, type conversion and --help for free.

It arrived in Python 2.7 and 3.2 as the replacement for optparse. You create an ArgumentParser, call add_argument() per flag, and get back an object with the attributes filled in. The help text is generated from the same declaration, which is the whole point — it cannot drift out of sync with the code.

It supports git commit-style subcommands, mutually exclusive groups and custom type functions. The ecosystem alternatives are click and typer, which are nicer but add a dependency.

← Back to the lexicon