This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Python Pluggable Shell Interface

Project Description
Pypsi - Python Pluggable Shell Interface

.. image::

.. image::

Develop extensible and powerful command line interface shells with minimal code. Want to jump straight into the API? Take a look at :doc:`pypsi.tutorial`.

Python Pluggable Shell Interface, or pypsi, is a framework for developing
command line based shell interfaces, akin to bash or csh. It is intended to be
a replacement for the builtin Python ``cmd`` module.

Pypsi is targetted towards both rapid prototype interfaces and large stable
shells. The bootstraping code is very small with very little boilerplate. Pypsi
ships with a great deal of capabilities out of the box, all of which can be used
or ignored. Pypsi is pluggable which allows commands, features, and plugins to be
developed independently in their own source files and/or Python classes. This
results in a very clean source repository. The actual code to setup and run the
shell is exetremely small, on the order of ~20-50 lines of code.

Pypsi, at its core, is pluggable. There are many hooks that allow plugin authors
to extend and modify the core behavior of pypsi. Commands are isolated classes
that make distribution, sharing, and modification easy.


The pypsi source code is hosted at `GitHub <>`_
and releases are stored at `PyPI <>`_. The
latest version can also be install via pip:


$ pip install pypsi

Documentation can be found on `GitHub Pages <>`_.


The following capabilities ship with pypsi and are available out of the box.

- I/O redirection
- Flexible API
- Tab completion
- Multiplatform
- Minimal dependencies
- Colors
- Session tips and message of the day (MOTD)
- Automated help, usage messages, and argument parsing
- Word wrapping
- Term highlighting (grep)
- Tables
- Prompt wizards
- ``cmd`` plugin to migrate existing ``cmd`` commands into pypsi


The ```` source file can be run to show off some of the base commands and
features that ship with pypsi (the ```` file can be downloaded from the
git repo at The commands
displayed below are all optional: pypsi does not require the use of any command
or plugin. The ```` file is meant to be a reference to the Pypsi API and
design. Use it as a starting point for your first shell.



pypsi)> var name = "Paul"

pypsi)> var house = "Atredis"

pypsi)> echo My name is $name, and I belong to House $house

My name is Paul, and I belong to House Atredis

pypsi)> var -l

name Paul
house Atredis

pypsi)> var -d name

pypsi)> echo $name

pypsi)> var name = "Paul $house"

pypsi)> echo $name

Paul Atredis

I/O redirection


pypsi)> echo Hello


pypsi)> echo Hello > output.txt

pypsi)> echo Goodbye

pypsi)> xargs -I{} "echo line: {}" < output.txt

line: Hello
line: Goodbye

pypsi)> cat output.txt | grep ll


System commands

Allows execution of external applications. Command mimics Python's
``os.system()`` function.


pypsi)> ls

pypsi: ls: command not found

pypsi)> system ls


pypsi)> system ls | system grep md

Fallback command

Allows the developer to set which command gets called if one does not exist in
the current shell. This is very useful, for example, if you want to fallback on
any OS installed executables. In this example, the fallback command is


pypsi)> ls


Command chaining


pypsi)> echo Hello && echo --bad-arg && echo goodbye

echo: unrecgonized arguments: --bad-arg

pypsi)> echo Hello ; echo --bad-arg ; echo goodbye

echo: unrecgonized arguments: --bad-arg

pypsi)> echo --bad-arg || echo first failed

echo: unrecgonized arguments: --bad-arg
first failed

Multiline commands


pypsi)> echo Hello, \
> Dave

Hello, Dave

pypsi)> echo This \
> is \
> pypsi \
> and it rocks

This is pypsi and it rocks


Macros are analogous to functions in bash. They provide the ability to create
new commands in the shell.


pypsi)> macro hello
> echo Hello, $1
> echo Goodbye from macro $0
> end

pypsi)> hello Adam

Hello, Adam
Goodbye from macro hello

Tab Complete

Tab completion is easier than ever with PyPsi. Using the included ``command_completer()``
function, arguments and sub-commands are completed automatically when the ``tab``
key is pressed. To get started, add the use of ``command_completer`` to your
custom command's complete function:

.. code-block:: python

def complete(self, shell, args, prefix):
from pypsi.completers import command_completer
return completions = command_completer(self.parser, shell, args, prefix)

Just pass ``command_completer`` the parser you created for the command, along with
the standard arguments to the ``complete`` function, and let PyPsi work it's magic!


pypsi)> macro -<tab>
--delete --help --list --show -d -h -l -s

For each argument added to a PyPsi Argument parser, a callback function to get
the possible completions can be specified via the `completer` argument.
The callback function will be called from ``command_completer`` anytime tab is
pressed while the user is currently entering that argument's value. Ex:

.. code-block:: python

# Snippet from
'-s', '--show', help='print macro body',
metavar='NAME', completer=self.complete_macros
def complete_macros(self, shell, args, prefix):
# returns a list of macro names in the current shell
return list(shell.ctx.macros.keys())


pypsi)> macro --show <tab>
hello goodbye

See ````, ````, and ```` for examples.

Prompt Wizards

Prompt wizards ask the user a series of questions and request input. Input is
tab completed, validated, and returned. The wizard can be used for easy
configuration of components that require a substantial amount of input.


pypsi)> wizard
| Entering Example Configuration Wizard |
Shows various examples of wizard steps

To exit, enter either Ctrl+C, Ctrl+D, or 'quit'. For help about the current
step, enter 'help' or '?'.

IP Address: <enter>

Error: Value is required
Local IP Address or Host name

IP Address:

TCP Port [1337]: <enter>

File path: /var/lo<tab>

local/ lock/ log/

File path: /var/log/<tab>

Xorg.1.log btmp faillog upstart/
Xorg.1.log.old dist-upgrade/ fontconfig.log wtmp
alternatives.log distccd.log fsck/
apt/ dmesg lastlog
bootstrap.log dpkg.log mongodb/

File path: /var/log/dpkg.log

Shell mode [local]: asdf

Error: Invalid choice

Mode of the shell

Shell mode [local]: remote

Config ID Config Value
port 1337
path /var/log/dpkg.log
mode remote


I developed Pypsi while working on a commerical product with a command line
interface. Originally, we used the ``cmd`` module, which was fine when we only
had a few commands that didn't accept complex arguments. As we added more
commands and more features, maintainability and extensibility became extremely
complicated and time consuming.

I took what I had learned from the ``cmd`` module, ORM libraries such as
MongoEngine, and features from proven great command line interfaces such as Git
and then I developed Pypsi. In order for Pypsi to be viable for our project, I
knew that Pypsi had to be compatible with ``cmd``, the porting process had to
take as little time as possible, and it had to be easy to understand and

The porting process from ``cmd`` to Pypsi for our commerical project took place
in January 2014. Since then, we've had 4 stable releases, had real world
feedback, and have successfully created many Pypsi commands and plugins with


``pypsi`` is released under the ISC premissive license.
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pypsi-1.4.1-py3-none-any.whl (91.4 kB) Copy SHA256 Checksum SHA256 3.5 Wheel Apr 5, 2017 (95.7 kB) Copy SHA256 Checksum SHA256 Source Apr 5, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting