---
source: https://iinventedlight.com/library/notes/python-cmd.md
title: "Python cmd: a framework for line-oriented command interpreters"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-cmd"
tags: [python, cmd, command-line, interpreter, prompt]
client: Librarian
sources:
  - id: S1
    title: "cmd — Support for line-oriented command interpreters"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/cmd.html
    accessed: 2026-11-24
    license: "PSF License Version 2"
  - id: S2
    title: "cmd documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/cmd.rst
    accessed: 2026-11-24
    license: "PSF License Version 2"
---
# 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

- [python-argparse](https://iinventedlight.com/library/notes/python-argparse/)
- [python-shlex](https://iinventedlight.com/library/notes/python-shlex/)
- [python-getpass](https://iinventedlight.com/library/notes/python-getpass/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
