Skip to main content

Python Pluggable Shell Interface

Project description

Python Pluggable Shell Interface, or pypsi, is a framework for developing command line based shell interfaces, akin to bash or csh.

Pypsi was designed around the Python cmd module. The Python cmd module is fine for small projects with a limited number of commands and features. However, as the interface grows, maintainability and extensibility becomes increasingly hard. Adding features such as argument parsing after a few commands have been implemented is extremely time consuming.

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 box of the box, all of which can be used or ignore. Pypsi is pluggable which allows commands, features, and plugins 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 modifing easy.

Caveats

The only major caveat when using pypsi is that it only supports Python 3. Python 3 is the future.

Releases

The pypsi source code is located on GitHub and on PyPI. The latest version can also be install via pip:

pip install pypsi

Features

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

  • I/O redirection

  • String-based pipes

  • 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

Demo

The demo.py source file can be run to show off some of the base commands and features that ship with pypsi (the demo.py file can be downloaded from the git repo at https://github.com/ameily/pypsi/blob/master/demo.py). The commands displayed below are all optional: pypsi does not require the use of any command or plugin.

Variables

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
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
Hello

System commands

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

pypsi)> ls
pypsi: ls: command not found
pypsi)> system ls
include/
src/
README.md
pypsi)> system ls | system grep md
README.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 system.

pypsi)> ls
include/
src/
README.md

Command chaining

pypsi)> echo Hello && echo --bad-arg && echo goodbye
Hello
echo: unrecgonized arguments: --bad-arg
pypsi)> echo Hello ; echo --bad-arg ; echo goodbye
Hello
echo: unrecgonized arguments: --bad-arg
goodbye
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

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

License

pypsi is released under the BSD 3-Clause license.

Project details


Download files

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

Source Distribution

pypsi-1.1.tar.gz (41.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pypsi-1.1.win-amd64.exe (299.6 kB view details)

Uploaded Source

pypsi-1.1.win32.exe (268.4 kB view details)

Uploaded Source

pypsi-1.1-py3-none-any.whl (77.3 kB view details)

Uploaded Python 3

File details

Details for the file pypsi-1.1.tar.gz.

File metadata

  • Download URL: pypsi-1.1.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pypsi-1.1.tar.gz
Algorithm Hash digest
SHA256 3fe9d8c78fd5850adf5c0cdc214eed755022e95286e8fa1e3fcf58a13e3d5049
MD5 30207f1a6e7c48bc3b75ee9570b145c5
BLAKE2b-256 44c3e4cd3ef54ec43458993562bbb652109f4a8a6af688b3bf7ed4f6b4291a72

See more details on using hashes here.

File details

Details for the file pypsi-1.1.win-amd64.exe.

File metadata

  • Download URL: pypsi-1.1.win-amd64.exe
  • Upload date:
  • Size: 299.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pypsi-1.1.win-amd64.exe
Algorithm Hash digest
SHA256 d8185d3ba29fcd346995efc59f224297319794abb6aaba6837e691fbe11d8def
MD5 5e27e1b907ca5b86c7a3ea1842df28f2
BLAKE2b-256 d0feea6f75def7e281eadb6a623acd60903968117bf6ca579eccc714dfb9b0b8

See more details on using hashes here.

File details

Details for the file pypsi-1.1.win32.exe.

File metadata

  • Download URL: pypsi-1.1.win32.exe
  • Upload date:
  • Size: 268.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pypsi-1.1.win32.exe
Algorithm Hash digest
SHA256 1c2ce50633fe1c27540d71184d50c92cb43788aafb1c925f2e089a7e0f6f3eac
MD5 db465ce8ee01203ddd232103f370c8c1
BLAKE2b-256 a5ca1e34e837067c9d138522ee5b8e3ccb4134b65863a35114b700e322ce1363

See more details on using hashes here.

File details

Details for the file pypsi-1.1-py3-none-any.whl.

File metadata

  • Download URL: pypsi-1.1-py3-none-any.whl
  • Upload date:
  • Size: 77.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pypsi-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 99713ae6bfc66a335b3c23cb2f6980e041219fe52b8d1fcdd5df7c4971fcf07b
MD5 0c1fd6098860ccc9e32c541590e803df
BLAKE2b-256 1e0cfc3b577e7e8e1a0f108ae0bd60e842b690edfd349c2aca4c940d48ca063c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page