cmd2
cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python
What it is and what it does
cmd2 extends Python's built-in cmd module to simplify building feature-rich interactive command-line applications. It provides automatic tab completion for commands, subcommands, file paths, and argparse-defined flags; rich help text generation; and scripting capabilities through text files and Python scripts. The framework is designed to bridge the gap between easy command discovery (via completion and help) and workflow automation (via aliases, macros, and scripting), making it suitable for both exploratory CLI tools and production automation systems.
The package depends on prompt-toolkit for terminal interaction, rich for colored output and formatting, rich-argparse for integrated argument help, and pyperclip for clipboard support. It has been actively maintained since 2008 and currently targets Python 3.11 and later, including free-threaded Python variants. With no known security vulnerabilities and a permissive MIT license, it is production-ready for developers building admin tools, interactive shells, or complex CLI workflows.
Use it for:
- Build system administration tools with discoverable commands and tab completion for file paths and options.
- Create interactive debugging or diagnostic shells that support scripting and command history.
- Develop workflow automation CLIs that transition smoothly from interactive exploration to batch scripting.
- Implement interactive REPL-style applications for data analysis or configuration management.
- Build security or penetration testing frameworks with command aliasing and macro support.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
cmd2 is a Python framework for building interactive command-line applications with built-in tab completion, help text generation, scripting, and automation features.
Yes. cmd2 is actively maintained, has low install friction, carries no security vulnerabilities, and uses a permissive MIT license. It is well-suited for any Python developer building interactive CLI applications that need tab completion, help generation, and scripting support. The framework is production-stable (Development Status 5) and supports current Python versions.
Install
cmd2 on PyPI
pip
pip install cmd2uv
uv add cmd2poetry
poetry add cmd2Installing cmd2
Before you install
Low install friction with only 4 runtime dependencies (prompt-toolkit, pyperclip, rich, rich-argparse). Actively maintained with a release 8 days ago. Supports current Python versions (3.11+) including free-threaded variants.
License in practice
MIT license permits commercial and private use with minimal restrictions—suitable for most projects without licensing concerns.
Quickstart
pip install cmd2
import cmd2
class MyApp(cmd2.Cmd):
def do_hello(self, _: cmd2.Statement):
self.poutput('Hello')
if __name__ == '__main__':
MyApp().cmdloop()
Requires Python 3.11 or later.
Verify before relying
- Whether the framework supports subcommand hierarchies beyond what argparse provides.
- Performance characteristics when handling large command sets or high-frequency tab completion.
- Compatibility with async/await patterns in user-defined commands.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — prompt-toolkit, pyperclip, rich, rich-argparse |
| Maintenance | actively maintained — 8 days since the last release |
| First released | |
| Downloads | 2,372,794/month — #3,099 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cmd2-4.2.0-py3-none-any.whl
Keywords: CLI, cmd, command, interactive, prompt, Python
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
click-shellConverts a click command-line app into an…
permissive · top 15,000 on PyPI
shtabGenerates shell tab completion scripts for…
copyleft · top 5,000 on PyPI
rich-toolkitRich Toolkit provides opinionated CLI…
permissive · top 1,000 on PyPI
clickClick is a Python toolkit for building…
permissive · top 100 on PyPI
argcompleteProvides bash and zsh tab completion for Python…
permissive · top 1,000 on PyPI
frida-toolsProvides command-line tools for Frida, a…
unclear · top 15,000 on PyPI
tabcompleterAdds Tab-key autocompletion and command…
permissive · top 5,000 on PyPI
arghArgh turns plain Python functions into…
copyleft · top 5,000 on PyPI
click-help-colorsAdds color customization to Click command-line…
permissive · top 5,000 on PyPI
iterm2Provides a Python scripting interface to…
copyleft · top 15,000 on PyPI