Registry / http-networking / cmd2

cmd2

JSON →
library3.4.0pypypi✓ verified 35d ago

cmd2 is a powerful Python library for quickly building feature-rich and user-friendly interactive command-line applications. It extends Python's built-in `cmd` module, providing a comprehensive set of enhancements including robust tab completion, searchable command history, text and Python scripting, and advanced argument parsing with `argparse`. The library is actively maintained with a frequent release cadence, continuously improving its capabilities and user experience.

http-networkingserialization
Install & Compatibility
Where this runs
tested against v3.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.555s · 31.7MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 2.9s · import 0.502s · 32MB
36MB installed
● package 36MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from cmd2 import Cmd

Commonly used for type hinting command arguments, especially when not using @with_argparser.

from cmd2 import Statement

This minimal example demonstrates how to create a basic `cmd2` application by subclassing `cmd2.Cmd` and defining a `do_` method for a command. Running `cmdloop()` starts the interactive shell, and you can type `hello_world` or `quit` to exit.

import cmd2 import sys class FirstApp(cmd2.Cmd): """A simple cmd2 application.""" def do_hello_world(self, _: cmd2.Statement): """Says hello to the world.""" self.poutput('Hello World') if __name__ == '__main__': c = FirstApp() sys.exit(c.cmdloop())
cmd2 --version
Debug
Known footguns
breakingMajor breaking changes occurred in `cmd2` version 3.x (from 2.x). Key changes include a new dependency on `prompt-toolkit` (replacing all `readline` usage) and `rich` for formatting. The Transcript Testing feature was removed, and `completer` and `choices_provider` functions now return `cmd2.Completions` and `cmd2.Choices` objects instead of lists of strings.
breaking`cmd2` dropped support for Python 3.8 in version 2.6.0, and Python 3.5 support ended in version 2.0.0. Current versions require Python 3.10+.
breakingThe `Cmd.cmdqueue` attribute, which was used in Python's built-in `cmd` module for queued input lines, was removed in `cmd2` version 0.9.13.
gotchaUnlike Python's standard `cmd` module, `cmd2` completely ignores empty lines entered at the prompt by default. The `cmd.emptyline()` method (which, by default, repeats the last command) is never called in `cmd2`.
deprecatedUsing `py run('myscript.py')` to execute Python scripts is deprecated. The `pyscript` command is now the recommended method, offering improved features like tab-completion of file system paths and the ability to pass command-line arguments.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
16 hits · last 30 days
bytedance
6
gptbot
4
ahrefsbot
4
script
1
Resources