cmd2 4.2.4


pip install cmd2

  Latest version

Released: Sep 08, 2026

Project Links

Meta
Author: cmd2 Contributors
Requires Python: >=3.11

Classifiers

Development Status
  • 5 - Production/Stable

Environment
  • Console

Operating System
  • OS Independent

Intended Audience
  • Developers
  • System Administrators

Programming Language
  • Python :: 3 :: Only
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14
  • Python :: 3.15
  • Python :: Free Threading :: 3 - Stable

Topic
  • Software Development :: Libraries :: Python Modules

cmd2: build feature-rich command-line applications 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. 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 Name Description Organization or Author
CephFS Shell The Ceph File System, or CephFS, is a POSIX-compliant file system built on top of Ceph’s distributed object store ceph
garak LLM vulnerability scanner that checks if an LLM can be made to fail in a way we don't want NVIDIA
Argus The Ultimate Information Gathering Toolkit JASON13
medusa Binary instrumentation framework that that automates processes for the dynamic analysis of Android and iOS Applications Ch0pin
InternalBlue Bluetooth experimentation framework for Broadcom and Cypress chips Secure Mobile Networking Lab
SCCMHunter A post-ex tool built to streamline identifying, profiling, and attacking SCCM related assets in an Active Directory domain Garret Foster
Unipacker Automatic and platform-independent unpacker for Windows binaries based on emulation unipacker
Frankenstein Broadcom and Cypress firmware emulation for fuzzing and further full-stack debugging Secure Mobile Networking Lab
Poseidon Leverages software-defined networks (SDNs) to acquire and then feed network traffic to a number of machine learning techniques. Faucet SDN
DFTimewolf A framework for orchestrating forensic collection, processing and data export log2timeline
LazyOwn The first RedTeam/APT Framework with an AI-powered C&C, featuring rootkits to conceal campaigns, undetectable malleable implants Grisuno
GAP SDK SDK for Greenwaves Technologies' GAP8 IoT Application Processor GreenWaves Technologies
REW Sploit Emulate and Dissect Metasploit Framework (MSF) and other attacks REW-sploit
tomcatmanager A command line tool and python library for managing a tomcat server tomcatmanager
Falcon Toolkit Unleash the power of the CrowdStrike Falcon Platform at the CLI CrowdStrike
EXPLIoT Internet of Things Security Testing and Exploitation framework expliot_framework
Pobshell A Bash‑like shell for live Python objects: cd, ls, cat, find and CLI piping for object code, str values & more Peter Dalloz
Wtsh WTSH is a shell built with Python cmd2(v4), which uses third-party plugins to construct a universal shell installed via Pip wazzge

Possibly defunct but still good examples

Application Name Description Organization or Author
Katana Automatic CTF Challenge Solver John Hammond
SatanSword (in Chinese) Comprehensive Penetration Framework for Red Teaming Lucifer1993
Jok3r Network & Web Pentest Automation Framework Koutto
Counterfit a CLI that provides a generic automation layer for assessing the security of ML models Microsoft Azure
Overlord Red Teaming Infrastructure Automation QSecure Labs
Automated Reconnaissance Pipeline An automated target reconnaissance pipeline epi052
JSShell An interactive multi-user web JavaScript (JS) shell Den1al
RedShell An interactive command prompt for red teaming and pentesting Verizon
FLASHMINGO Automatic analysis of SWF files based on some heuristics. Extensible via plugins. Mandiant
psiTurk An open platform for science on Amazon Mechanical Turk NYU 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.

4.2.4 Sep 08, 2026
4.2.3 Sep 02, 2026
4.2.2 Aug 25, 2026
4.2.1 Aug 22, 2026
4.2.0 Aug 06, 2026
4.1.2 Jul 16, 2026
4.1.1 Jul 09, 2026
4.1.0 Jul 07, 2026
4.0.1 Jul 07, 2026
4.0.0 Jun 05, 2026
4.0.0rc2 Jun 04, 2026
4.0.0rc1 May 15, 2026
4.0.0b6 Apr 29, 2026
4.0.0b5 Apr 23, 2026
4.0.0b4 Apr 20, 2026
4.0.0b3 Apr 19, 2026
4.0.0b2 Mar 24, 2026
4.0.0b1 Mar 03, 2026
3.5.1 Apr 24, 2026
3.5.0 Apr 13, 2026
3.4.0 Mar 03, 2026
3.3.0 Mar 01, 2026
3.2.2 Feb 21, 2026
3.2.1 Feb 21, 2026
3.2.0 Feb 05, 2026
3.1.3 Feb 03, 2026
3.1.2 Jan 27, 2026
3.1.1 Jan 27, 2026
3.1.0 Dec 25, 2025
3.0.0 Dec 07, 2025
3.0.0rc1 Sep 26, 2025
3.0.0b2 Sep 17, 2025
3.0.0b1 Sep 16, 2025
2.7.0 Jun 30, 2025
2.6.2 Jun 26, 2025
2.6.1 Jun 08, 2025
2.6.0 May 31, 2025
2.5.11 Jan 25, 2025
2.5.10 Jan 25, 2025
2.5.9 Jan 18, 2025
2.5.8 Dec 18, 2024
2.5.7 Nov 23, 2024
2.5.6 Nov 14, 2024
2.5.5 Nov 13, 2024
2.5.4 Nov 07, 2024
2.5.3 Nov 05, 2024
2.5.2 Nov 03, 2024
2.5.1 Nov 02, 2024
2.5.0 Oct 24, 2024
2.4.3 Jan 28, 2023
2.4.2 Jul 13, 2022
2.4.1 Apr 13, 2022
2.4.0 Feb 23, 2022
2.3.3 Nov 29, 2021
2.3.2 Nov 22, 2021
2.3.1 Nov 19, 2021
2.3.0 Nov 11, 2021
2.2.0 Sep 14, 2021
2.1.2 Jul 05, 2021
2.1.1 Jun 17, 2021
2.1.0 Jun 14, 2021
2.0.1 Jun 07, 2021
2.0.0 Jun 07, 2021
1.5.0 Jan 31, 2021
1.4.0 Nov 12, 2020
1.3.11 Oct 01, 2020
1.3.10 Sep 18, 2020
1.3.9 Sep 04, 2020
1.3.8 Aug 28, 2020
1.3.7 Aug 27, 2020
1.3.6 Aug 27, 2020
1.3.5 Aug 25, 2020
1.3.4 Aug 20, 2020
1.3.3 Aug 13, 2020
1.3.2 Aug 10, 2020
1.3.1 Aug 06, 2020
1.3.0 Aug 04, 2020
1.2.1 Jul 14, 2020
1.2.0 Jul 14, 2020
1.1.0 Jun 06, 2020
1.0.2 Apr 06, 2020
1.0.1 Mar 13, 2020
1.0.0 Mar 01, 2020
0.10.1 Feb 19, 2020
0.10.0 Feb 08, 2020
0.9.25 Jan 26, 2020
0.9.24 Jan 24, 2020
0.9.23 Jan 10, 2020
0.9.22 Dec 10, 2019
0.9.21 Nov 26, 2019
0.9.20 Nov 13, 2019
0.9.19 Oct 14, 2019
0.9.18 Oct 01, 2019
0.9.17 Sep 24, 2019
0.9.16 Aug 08, 2019
0.9.15 Jul 25, 2019
0.9.14 Jun 29, 2019
0.9.13 Jun 15, 2019
0.9.12 Apr 23, 2019
0.9.11 Mar 13, 2019
0.9.10 Feb 22, 2019
0.9.9 Feb 22, 2019
0.9.8 Feb 07, 2019
0.9.7 Jan 09, 2019
0.9.6 Oct 13, 2018
0.9.5 Oct 11, 2018
0.9.4 Aug 21, 2018
0.9.3 Jul 12, 2018
0.9.2 Jun 29, 2018
0.9.1 May 28, 2018
0.9.0.1 May 28, 2018
0.8.9 Aug 21, 2018
0.8.8 Jun 29, 2018
0.8.7 May 28, 2018
0.8.7rc1 May 28, 2018
0.8.6.1 May 28, 2018
0.8.6 May 27, 2018
0.8.5 Apr 15, 2018
0.8.4 Apr 10, 2018
0.8.3 Apr 09, 2018
0.8.2 Mar 21, 2018
0.8.1 Mar 10, 2018
0.8.0 Feb 01, 2018
0.7.9 Jan 04, 2018
0.7.8 Nov 09, 2017
0.7.7 Aug 25, 2017
0.7.6 Aug 11, 2017
0.7.5 Jul 08, 2017
0.7.4 Jul 03, 2017
0.7.3 Jun 23, 2017
0.7.2 May 22, 2017
0.7.1 May 22, 2017
0.7.0 Feb 23, 2017
0.6.9 Oct 03, 2016
0.6.8 Dec 09, 2014
0.6.7 Sep 21, 2013
0.6.6.1 Aug 14, 2013
0.6.6 Aug 06, 2013
0.6.5.1 Mar 18, 2013
0.6.5 Feb 28, 2013
0.6.4 May 27, 2012
0.6.3 Jul 29, 2011
0.6.2 Nov 09, 2010
0.6.1 Mar 03, 2010
0.6.0 Feb 18, 2010
0.5.5 Aug 08, 2009
0.5.4 Jun 02, 2009
0.5.3 Apr 30, 2009
0.5.2 Apr 03, 2009
0.5.1 Mar 30, 2009
0.5.0 Mar 24, 2009
0.4.8 Mar 19, 2009
0.4.7 Mar 02, 2009
0.4.6 Feb 25, 2009
0.4.5 Jan 28, 2009
0.4.4 Dec 22, 2008
0.4.3 Nov 07, 2008
0.4.2 Nov 05, 2008
0.4.1 Oct 29, 2008
0.4 Oct 28, 2008
0.3.7 Sep 29, 2008
0.3.6 Sep 04, 2008
0.3.5 Aug 02, 2008
0.3.4.1 Jul 02, 2008
0.3.4 Jun 09, 2008
0.3.3 May 28, 2008
0.3.2 May 21, 2008
0.3.1 May 19, 2008
0.3.0 May 15, 2008
0.2.3 May 14, 2008
0.2.2 Apr 11, 2008
0.2.1 Mar 03, 2008
0.2 Feb 26, 2008
0.1 Jan 06, 2008
0.6.0.py3 Feb 19, 2010
0.4.win32 Oct 28, 2008
0.4.4.win32 Dec 22, 2008
0.4.3.win32 Nov 07, 2008
0.4.1.win32 Oct 29, 2008
0.3.5.win32 Aug 04, 2008
0.3.4.win32 Jun 09, 2008
0.3.3.win32 May 28, 2008
0.2.win32 Feb 26, 2008
0.2.3.win32 May 14, 2008
0.2.2.win32 Apr 11, 2008
0.2.1.win32 Mar 05, 2008
0.1.win32 Jan 03, 2008

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras: None
Dependencies:
prompt-toolkit (>=3.0.53)
pyperclip (>=1.8.2)
rich (>=15.0.0)
rich-argparse (>=1.7.2)