A python package for building powerful command-line interpreter (CLI) programs. Extends the Python Standard Library’s cmd package.

The basic use of cmd2 is identical to that of cmd.

  1. Create a subclass of cmd2.Cmd. Define attributes and do_* methods to control its behavior. Throughout this documentation, we will assume that you are naming your subclass App:

    from cmd2 import Cmd
    class App(Cmd):
        # customized attributes and methods here
  2. Instantiate App and start the command loop:

    app = App()

Getting Started

Building a new REPL or Command Line Interface application?

Already built an application that uses cmd from the python standard library and want to add more functionality with very little work?

cmd2 is a powerful python library for building command line applications. Start here to find out if this library is a good fit for your needs.

Migrating from cmd

If you’re thinking of migrating your cmd app to cmd2, this section will help you decide if it’s right for your app, and show you how to do it.

  • Why cmd2 - we try and convince you to use cmd2 instead of cmd
  • Incompatibilities - cmd2 is not quite 100% compatible with cmd.
  • Minimum Required Changes - the minimum changes required to move from cmd to cmd2. Start your migration here.
  • Next Steps - Once you’ve migrated, here a list of things you can do next to add even more functionality to your app.