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
- id: C1 claim: optparse is a declarative replacement for getopt. source: S1 evidence: "a declarative replacement for getopt"
- id: C2 claim: argparse is the recommended choice for command line applications. source: S1 evidence: "argparse is the recommended choice"
- id: C3 claim: It supports only the most common Unix command line syntax. source: S2 evidence: "supports only the most common command-line syntax"
- id: C4 claim: These are the only two option syntaxes provided. source: S2 evidence: "These are the only two option syntaxes provided"
Sources
- [S1] optparse — Parser for command line options. Python Software Foundation. https://docs.python.org/3/library/optparse.html . License: PSF License Version 2. Accessed 2026-11-26.
- [S2] optparse documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/optparse.rst . License: PSF License Version 2. Accessed 2026-11-26.
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
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.},
}
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.
- python-optparse.schema.json (schema; CC-BY-4.0)
- python-optparse.table.json (table; CC-BY-4.0)
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.