{"id":3431,"library":"cmd2","title":"cmd2 - Feature-Rich Interactive Command Line Applications","description":"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.","status":"active","version":"3.4.0","language":"en","source_language":"en","source_url":"https://github.com/python-cmd2/cmd2","tags":["CLI","REPL","command-line interface","interactive","argparse","shell"],"install":[{"cmd":"pip install cmd2","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Provides cross-platform tab-completion, user terminal input, and history, replacing older readline dependencies.","package":"prompt-toolkit"},{"reason":"Used for rich text and pretty formatting in the terminal.","package":"rich"}],"imports":[{"symbol":"Cmd","correct":"from cmd2 import Cmd"},{"note":"Commonly used for type hinting command arguments, especially when not using @with_argparser.","symbol":"Statement","correct":"from cmd2 import Statement"}],"quickstart":{"code":"import cmd2\nimport sys\n\nclass FirstApp(cmd2.Cmd):\n    \"\"\"A simple cmd2 application.\"\"\"\n\n    def do_hello_world(self, _: cmd2.Statement):\n        \"\"\"Says hello to the world.\"\"\"\n        self.poutput('Hello World')\n\nif __name__ == '__main__':\n    c = FirstApp()\n    sys.exit(c.cmdloop())","lang":"python","description":"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."},"warnings":[{"fix":"Review the official 'Migration Guide' for upgrading from 2.x to 3.x in the cmd2 documentation. Adapt custom completer/choices_provider functions to return the new object types.","message":"Major 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.","severity":"breaking","affected_versions":"3.x and higher"},{"fix":"Ensure your project uses Python 3.10 or higher to be compatible with current `cmd2` versions.","message":"`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+.","severity":"breaking","affected_versions":"2.6.0+, 3.x+"},{"fix":"Avoid using `Cmd.cmdqueue`. `cmd2` provides alternative mechanisms for running commands via `cmdloop()`, text scripts, Python scripts, and history replays, which offer more consistent behavior.","message":"The `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.","severity":"breaking","affected_versions":"0.9.13+"},{"fix":"If you require custom behavior for empty lines, you will need to implement a post-parsing hook or similar mechanism to detect and handle them manually.","message":"Unlike 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`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate from `py run()` to the `pyscript` command for executing Python scripts within your `cmd2` application.","message":"Using `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.","severity":"deprecated","affected_versions":"Versions where `pyscript` is available"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}