Python cmd: a framework for line-oriented command interpreters
Answer: Cmd is a simple framework for writing line-oriented command interpreters.
How a session works
A command interpreter built with this class typically presents the user with an interactive prompt.
It reads input one line at a time.
It then dispatches each command to a method named do followed by the command name.
cmdloop repeatedly issues a prompt, accepts input, and dispatches to action methods.
How to extend it
These interpreters are often useful for test harnesses, administrative tools, and prototypes.
There is no good reason to instantiate Cmd itself.
It is useful as a superclass of an interpreter class you define yourself.
Most of the interpreter behavior is defined by the do methods you add in your own subclass.
See also
Claims
- id: C1 claim: Cmd is a simple framework for line-oriented command interpreters. source: S1 evidence: "simple framework for writing line-oriented command interpreters"
- id: C2 claim: Each command is dispatched to a method named do plus the command name. source: S1 evidence: "dispatches each command to a method named"
- id: C3 claim: These tools are often useful for test harnesses and administrative tools. source: S2 evidence: "useful for test harnesses, administrative tools, and prototypes"
- id: C4 claim: There is no good reason to instantiate Cmd itself. source: S2 evidence: "no good reason to instantiate"
Sources
- [S1] cmd — Support for line-oriented command interpreters. Python Software Foundation. https://docs.python.org/3/library/cmd.html . License: PSF License Version 2. Accessed 2026-11-24.
- [S2] cmd documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/cmd.rst . License: PSF License Version 2. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, cmd — Support for line-oriented command interpreters; CPython, cmd 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, cmd — Support for line-oriented command interpreters; CPython, cmd documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python cmd: a framework for line-oriented command interpreters." iinventedlight Library, iil:note:zekmd162, version of 2026-11-24. https://iinventedlight.com/library/notes/python-cmd/. License: CC-BY-4.0.
@misc{iil_note_zekmd162,
author = {{iinventedlight}},
title = {{Python cmd: a framework for line-oriented command interpreters}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/python-cmd/},
note = {Permanent ID iil:note:zekmd162. 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-cmd.schema.json (schema; CC-BY-4.0)
- python-cmd.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-cmd.md.