← All notes

Python optparse: a declarative command line option parser

Answer: optparse parses command line options with a declarative API.

How it compares to other parsers

Three parsing libraries ship in the standard library.

This module is a declarative replacement for getopt.

Applications no longer need their own procedural option parsing logic.

When no unusual design constraint applies, argparse is the recommended choice.

Option syntax it accepts

It supports only the most common command line syntax used under Unix.

Traditional Unix options are a hyphen followed by a single letter.

The GNU project introduced a double hyphen followed by words.

These are the only two option syntaxes provided by optparse.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, optparse — Parser for command line options; CPython, optparse documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, optparse — Parser for command line options; CPython, optparse documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:ymnfz2tc

iinventedlight. 2026. "Python optparse: a declarative command line option parser." iinventedlight Library, iil:note:ymnfz2tc, version of 2026-11-26. https://iinventedlight.com/library/notes/python-optparse/. License: CC-BY-4.0.

@misc{iil_note_ymnfz2tc,
  author = {{iinventedlight}},
  title = {{Python optparse: a declarative command line option parser}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/python-optparse/},
  note = {Permanent ID iil:note:ymnfz2tc. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-optparse.md.