python-cmd2/cmd2

cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python

Python

688

5,020 commits

updated Oct 18, 2026

See the code

See what people are saying

SourceMessageScoreDate

good list. I'm looking for something like this https://cmd2.readthedocs.io/en/stable/ for go. suggestions welcome.

on The Go libraries that never failed us: 22 libraries you need to know

0

Oct 3, 2024

README

cmd2 logo

cmd2: build feature-rich command-line apps in Python

Latest Version Tests codecov Documentation Status Chat

Quick start • Why cmd2? • Installation • Documentation • Projects using cmd2

cmd2 makes it quick to build powerful, polished command-line applications and REPLs in Python. Start with a subclass of the standard library's cmd.Cmd, then add commands while cmd2 handles the details that make an application pleasant to build and use: argument parsing, generated help, tab completion, command history, scripting, output styling, and much more.

You can use cmd2 for a small internal tool and grow the same application into an extensible, scriptable interface without replacing the framework or writing the usual CLI boilerplate.

Quick start

Install cmd2:

pip install cmd2

Then create app.py:

from typing import Annotated

import cmd2
from cmd2.annotated import Argument, Option


class App(cmd2.Cmd):
    """A small interactive application."""

    @cmd2.with_annotated
    def do_greet(
        self,
        name: Annotated[str, Argument(help_text="person to greet")],
        count: Annotated[int, Option(help_text="number of greetings")] = 1,
    ) -> None:
        """Greet a person."""
        for _ in range(count):
            self.poutput(f"Hello, {name}!")


if __name__ == "__main__":
    App().cmdloop()

cmd2 supports Typer-style syntax for specifying command arguments with type annotations. In this example, @cmd2.with_annotated turns name and count into a positional argument and an option.

Run it with python app.py. Your new greet command already has input validation, generated help, and tab completion for its options. The application also includes discoverable help, command history, aliases, macros, scripting, shell integration, and other built-in commands.

(Cmd) help greet
Usage: greet [-h] [--count COUNT] name

(Cmd) greet --count 2 Ada
Hello, Ada!
Hello, Ada!

Animated demonstration of the cmd2 quick-start application

See the getting started tutorial to build a more complete application.

Why cmd2?

Build more with less code

  • Define commands as Python methods and use familiar argparse parsers for arguments and subcommands, or plain type hints via @with_annotated. A single parser definition drives validation, help, and completion.
  • Render Rich tables and other styled objects, with consistent helpers for normal output, errors, warnings, and paging.
  • Organize large applications into independently testable and dynamically loadable CommandSets, and customize the command lifecycle with hooks.
  • Integrate existing Python code, shell tools, or asynchronous work instead of restructuring your application around the framework.
  • Run on Windows, macOS, and Linux with a pure-Python package and a small dependency footprint.

Give users a capable interface from day one

  • Tab completion: provide context-aware completion for commands, subcommands, options, choices, file paths, and custom data sources, with descriptive hints for completion candidates. Learn more about completion.
  • History: search, edit, rerun, save, and optionally persist previously entered commands. Users also get familiar navigation and reverse search such as Ctrl+R. Learn more about history.
  • Unicode: accept Unicode in commands, arguments, file names, and output, and run UTF-8 command scripts for applications used in any language. Learn more about command scripts.
  • Shell shortcuts and hotkeys: use familiar Readline-style keyboard shortcuts for navigating and editing the command line, including Emacs-style bindings provided by prompt-toolkit. Learn more about keyboard shortcuts.
  • Help: generate discoverable, categorized help for commands, subcommands, and arguments directly from their argument parsers. Learn more about help.
  • Rich UI/UX: offer syntax highlighting, Fish-style history suggestions, multiline input, configurable prompts, completion menus, themes, and an optional bottom toolbar. Learn more about prompts and toolbars and themes.

Grow from exploration to automation

  • Shell scripting: automate the same commands users run interactively by passing them as command arguments or standard input from shell scripts. Learn more about automating cmd2 applications.
  • Python scripting: run Python scripts inside the application for loops, branching, complex control flow, and integration with the application's commands and data. Learn more about Python scripts.
  • Run shell commands: execute operating-system commands without leaving the application, using the built-in shell command or its ! shortcut. Learn more about OS integration.
  • Redirect output: send command output to files or the clipboard, or pipe it through one or more shell commands. Learn more about output redirection and pipes.
  • Aliases, macros, and shortcuts: let users customize names, parameterized commands, and terse shortcuts for repetitive workflows without changing the application. Learn more about aliases, macros, and shortcuts.
  • Startup scripts: initialize an application consistently by running saved commands every time it starts. Learn more about startup commands and scripts.
  • Embedded Python and IPython shells: drop into an interactive Python or IPython session for experimentation, debugging, object introspection, and access to application state. Learn more about embedded Python shells.
  • Color, style, and tables: produce readable output with Rich colors and styles, custom themes, paging, and flexible table layouts. Learn more about generating output and creating tables.

Installation

On all operating systems, the latest stable version of cmd2 can be installed using pip:

pip install -U cmd2

cmd2 works with Python 3.11+ on Windows, macOS, and Linux. It is pure Python code with few 3rd-party dependencies. It works with both conventional CPython and free-threaded variants.

For information on other installation options, see Installation Instructions in the cmd2 documentation.

[!IMPORTANT] Upgrading from an older release? Versions 3.x and 4.x include significant backwards-incompatible changes. Review the changelog and migration guide before upgrading.

Documentation

Read the latest documentation online or download it in HTML, PDF, and ePub formats. The examples directory contains focused, runnable demonstrations of individual features.

Tutorials

Found a bug?

If you think you've found a bug, please first read through the open Issues. If you're confident it's a new bug, go ahead and create a new GitHub issue. Be sure to include as much information as possible so we can reproduce the bug. At a minimum, please state the following:

  • cmd2 version
  • Python version
  • OS name and version
  • What you did to cause the bug to occur
  • Include any traceback or error message associated with the bug

Projects using cmd2

Application NameDescriptionOrganization or Author
CephFS ShellThe Ceph File System, or CephFS, is a POSIX-compliant file system built on top of Ceph’s distributed object storeceph
garakLLM vulnerability scanner that checks if an LLM can be made to fail in a way we don't wantNVIDIA
ArgusThe Ultimate Information Gathering ToolkitJASON13
medusaBinary instrumentation framework that that automates processes for the dynamic analysis of Android and iOS ApplicationsCh0pin
InternalBlueBluetooth experimentation framework for Broadcom and Cypress chipsSecure Mobile Networking Lab
SCCMHunterA post-ex tool built to streamline identifying, profiling, and attacking SCCM related assets in an Active Directory domainGarret Foster
UnipackerAutomatic and platform-independent unpacker for Windows binaries based on emulationunipacker
FrankensteinBroadcom and Cypress firmware emulation for fuzzing and further full-stack debuggingSecure Mobile Networking Lab
PoseidonLeverages software-defined networks (SDNs) to acquire and then feed network traffic to a number of machine learning techniques.Faucet SDN
DFTimewolfA framework for orchestrating forensic collection, processing and data exportlog2timeline
LazyOwnThe first RedTeam/APT Framework with an AI-powered C&C, featuring rootkits to conceal campaigns, undetectable malleable implantsGrisuno
GAP SDKSDK for Greenwaves Technologies' GAP8 IoT Application ProcessorGreenWaves Technologies
REW SploitEmulate and Dissect Metasploit Framework (MSF) and other attacksREW-sploit
tomcatmanagerA command line tool and python library for managing a tomcat servertomcatmanager
Falcon ToolkitUnleash the power of the CrowdStrike Falcon Platform at the CLICrowdStrike
EXPLIoTInternet of Things Security Testing and Exploitation frameworkexpliot_framework
PobshellA Bash‑like shell for live Python objects: cd, ls, cat, find and CLI piping for object code, str values & morePeter Dalloz
WtshWTSH is a shell built with Python cmd2(v4), which uses third-party plugins to construct a universal shell installed via Pipwazzge

Possibly defunct but still good examples

Application NameDescriptionOrganization or Author
KatanaAutomatic CTF Challenge SolverJohn Hammond
SatanSword (in Chinese)Comprehensive Penetration Framework for Red TeamingLucifer1993
Jok3rNetwork & Web Pentest Automation FrameworkKoutto
Counterfita CLI that provides a generic automation layer for assessing the security of ML modelsMicrosoft Azure
OverlordRed Teaming Infrastructure AutomationQSecure Labs
Automated Reconnaissance PipelineAn automated target reconnaissance pipelineepi052
JSShellAn interactive multi-user web JavaScript (JS) shellDen1al
RedShellAn interactive command prompt for red teaming and pentestingVerizon
FLASHMINGOAutomatic analysis of SWF files based on some heuristics. Extensible via plugins.Mandiant
psiTurkAn open platform for science on Amazon Mechanical TurkNYU Computation and Cognition Lab

Note: If you have created an application based on cmd2 that you would like us to mention here, please get in touch.

auto-completion
cli
command-line
developer-tools
python
scripting
shell
subcommands
tab-completion
terminal
unicode

python-cmd2/cmd2

cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python

Python

688

5,020 commits

updated Oct 18, 2026

See the code

See what people are saying

SourceMessageScoreDate

good list. I'm looking for something like this https://cmd2.readthedocs.io/en/stable/ for go. suggestions welcome.

on The Go libraries that never failed us: 22 libraries you need to know

0

Oct 3, 2024

README

cmd2 logo

cmd2: build feature-rich command-line apps in Python

Latest Version Tests codecov Documentation Status Chat

Quick start • Why cmd2? • Installation • Documentation • Projects using cmd2

cmd2 makes it quick to build powerful, polished command-line applications and REPLs in Python. Start with a subclass of the standard library's cmd.Cmd, then add commands while cmd2 handles the details that make an application pleasant to build and use: argument parsing, generated help, tab completion, command history, scripting, output styling, and much more.

You can use cmd2 for a small internal tool and grow the same application into an extensible, scriptable interface without replacing the framework or writing the usual CLI boilerplate.

Quick start

Install cmd2:

pip install cmd2

Then create app.py:

from typing import Annotated

import cmd2
from cmd2.annotated import Argument, Option


class App(cmd2.Cmd):
    """A small interactive application."""

    @cmd2.with_annotated
    def do_greet(
        self,
        name: Annotated[str, Argument(help_text="person to greet")],
        count: Annotated[int, Option(help_text="number of greetings")] = 1,
    ) -> None:
        """Greet a person."""
        for _ in range(count):
            self.poutput(f"Hello, {name}!")


if __name__ == "__main__":
    App().cmdloop()

cmd2 supports Typer-style syntax for specifying command arguments with type annotations. In this example, @cmd2.with_annotated turns name and count into a positional argument and an option.

Run it with python app.py. Your new greet command already has input validation, generated help, and tab completion for its options. The application also includes discoverable help, command history, aliases, macros, scripting, shell integration, and other built-in commands.

(Cmd) help greet
Usage: greet [-h] [--count COUNT] name

(Cmd) greet --count 2 Ada
Hello, Ada!
Hello, Ada!

Animated demonstration of the cmd2 quick-start application

See the getting started tutorial to build a more complete application.

Why cmd2?

Build more with less code

  • Define commands as Python methods and use familiar argparse parsers for arguments and subcommands, or plain type hints via @with_annotated. A single parser definition drives validation, help, and completion.
  • Render Rich tables and other styled objects, with consistent helpers for normal output, errors, warnings, and paging.
  • Organize large applications into independently testable and dynamically loadable CommandSets, and customize the command lifecycle with hooks.
  • Integrate existing Python code, shell tools, or asynchronous work instead of restructuring your application around the framework.
  • Run on Windows, macOS, and Linux with a pure-Python package and a small dependency footprint.

Give users a capable interface from day one

  • Tab completion: provide context-aware completion for commands, subcommands, options, choices, file paths, and custom data sources, with descriptive hints for completion candidates. Learn more about completion.
  • History: search, edit, rerun, save, and optionally persist previously entered commands. Users also get familiar navigation and reverse search such as Ctrl+R. Learn more about history.
  • Unicode: accept Unicode in commands, arguments, file names, and output, and run UTF-8 command scripts for applications used in any language. Learn more about command scripts.
  • Shell shortcuts and hotkeys: use familiar Readline-style keyboard shortcuts for navigating and editing the command line, including Emacs-style bindings provided by prompt-toolkit. Learn more about keyboard shortcuts.
  • Help: generate discoverable, categorized help for commands, subcommands, and arguments directly from their argument parsers. Learn more about help.
  • Rich UI/UX: offer syntax highlighting, Fish-style history suggestions, multiline input, configurable prompts, completion menus, themes, and an optional bottom toolbar. Learn more about prompts and toolbars and themes.

Grow from exploration to automation

  • Shell scripting: automate the same commands users run interactively by passing them as command arguments or standard input from shell scripts. Learn more about automating cmd2 applications.
  • Python scripting: run Python scripts inside the application for loops, branching, complex control flow, and integration with the application's commands and data. Learn more about Python scripts.
  • Run shell commands: execute operating-system commands without leaving the application, using the built-in shell command or its ! shortcut. Learn more about OS integration.
  • Redirect output: send command output to files or the clipboard, or pipe it through one or more shell commands. Learn more about output redirection and pipes.
  • Aliases, macros, and shortcuts: let users customize names, parameterized commands, and terse shortcuts for repetitive workflows without changing the application. Learn more about aliases, macros, and shortcuts.
  • Startup scripts: initialize an application consistently by running saved commands every time it starts. Learn more about startup commands and scripts.
  • Embedded Python and IPython shells: drop into an interactive Python or IPython session for experimentation, debugging, object introspection, and access to application state. Learn more about embedded Python shells.
  • Color, style, and tables: produce readable output with Rich colors and styles, custom themes, paging, and flexible table layouts. Learn more about generating output and creating tables.

Installation

On all operating systems, the latest stable version of cmd2 can be installed using pip:

pip install -U cmd2

cmd2 works with Python 3.11+ on Windows, macOS, and Linux. It is pure Python code with few 3rd-party dependencies. It works with both conventional CPython and free-threaded variants.

For information on other installation options, see Installation Instructions in the cmd2 documentation.

[!IMPORTANT] Upgrading from an older release? Versions 3.x and 4.x include significant backwards-incompatible changes. Review the changelog and migration guide before upgrading.

Documentation

Read the latest documentation online or download it in HTML, PDF, and ePub formats. The examples directory contains focused, runnable demonstrations of individual features.

Tutorials

Found a bug?

If you think you've found a bug, please first read through the open Issues. If you're confident it's a new bug, go ahead and create a new GitHub issue. Be sure to include as much information as possible so we can reproduce the bug. At a minimum, please state the following:

  • cmd2 version
  • Python version
  • OS name and version
  • What you did to cause the bug to occur
  • Include any traceback or error message associated with the bug

Projects using cmd2

Application NameDescriptionOrganization or Author
CephFS ShellThe Ceph File System, or CephFS, is a POSIX-compliant file system built on top of Ceph’s distributed object storeceph
garakLLM vulnerability scanner that checks if an LLM can be made to fail in a way we don't wantNVIDIA
ArgusThe Ultimate Information Gathering ToolkitJASON13
medusaBinary instrumentation framework that that automates processes for the dynamic analysis of Android and iOS ApplicationsCh0pin
InternalBlueBluetooth experimentation framework for Broadcom and Cypress chipsSecure Mobile Networking Lab
SCCMHunterA post-ex tool built to streamline identifying, profiling, and attacking SCCM related assets in an Active Directory domainGarret Foster
UnipackerAutomatic and platform-independent unpacker for Windows binaries based on emulationunipacker
FrankensteinBroadcom and Cypress firmware emulation for fuzzing and further full-stack debuggingSecure Mobile Networking Lab
PoseidonLeverages software-defined networks (SDNs) to acquire and then feed network traffic to a number of machine learning techniques.Faucet SDN
DFTimewolfA framework for orchestrating forensic collection, processing and data exportlog2timeline
LazyOwnThe first RedTeam/APT Framework with an AI-powered C&C, featuring rootkits to conceal campaigns, undetectable malleable implantsGrisuno
GAP SDKSDK for Greenwaves Technologies' GAP8 IoT Application ProcessorGreenWaves Technologies
REW SploitEmulate and Dissect Metasploit Framework (MSF) and other attacksREW-sploit
tomcatmanagerA command line tool and python library for managing a tomcat servertomcatmanager
Falcon ToolkitUnleash the power of the CrowdStrike Falcon Platform at the CLICrowdStrike
EXPLIoTInternet of Things Security Testing and Exploitation frameworkexpliot_framework
PobshellA Bash‑like shell for live Python objects: cd, ls, cat, find and CLI piping for object code, str values & morePeter Dalloz
WtshWTSH is a shell built with Python cmd2(v4), which uses third-party plugins to construct a universal shell installed via Pipwazzge

Possibly defunct but still good examples

Application NameDescriptionOrganization or Author
KatanaAutomatic CTF Challenge SolverJohn Hammond
SatanSword (in Chinese)Comprehensive Penetration Framework for Red TeamingLucifer1993
Jok3rNetwork & Web Pentest Automation FrameworkKoutto
Counterfita CLI that provides a generic automation layer for assessing the security of ML modelsMicrosoft Azure
OverlordRed Teaming Infrastructure AutomationQSecure Labs
Automated Reconnaissance PipelineAn automated target reconnaissance pipelineepi052
JSShellAn interactive multi-user web JavaScript (JS) shellDen1al
RedShellAn interactive command prompt for red teaming and pentestingVerizon
FLASHMINGOAutomatic analysis of SWF files based on some heuristics. Extensible via plugins.Mandiant
psiTurkAn open platform for science on Amazon Mechanical TurkNYU Computation and Cognition Lab

Note: If you have created an application based on cmd2 that you would like us to mention here, please get in touch.

auto-completion
cli
command-line
developer-tools
python
scripting
shell
subcommands
tab-completion
terminal
unicode

Project health

Overall

5.1/10

Maintained

10/10

Code review

1/10
OpenSSF Scorecard

PyPI

Latest release

4.3.0 · Oct 13, 2026

Releases this year

23

Significant stargazers

TheTechromancer

315 followers · starred Sep 2024

Randy Lai

568 followers · starred Aug 2018

TennyZhuang

1,540 followers · starred Mar 2025

Spencer McIntyre

689 followers · starred Nov 2017