Skip to content

Shell in Python

Existing Python libraries

Python-based shells

  • is a shell. The main idea is to rely on piping as the primary means of composition, as with any Unix or Linux shell. However, instead of passing strings from one command to the next, marcel passes Python values: builtin types such as lists, tuples, strings, and numbers; but also objects representing files and processes.”
  • “Xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt. The language is a superset of Python 3.6+ with additional shell primitives that you are used to from Bash and IPython. It works on all major systems including Linux, OSX, and Windows. Xonsh is meant for the daily use of experts and novices.”

Docs / blogs posts

Shell -> Python converter / compiler

See also:

Type-safe shell scripting



Misc ideas for a new API


  • Ease / naturalness of use
  • Type safety

Shell object: shell = Shell()

Run something: result =

With options: result = (== ls -l).

Errors recovery:

    result =
except ShellException as e:

Strong typing: generate .pyi files for common commands ? By parsing man pages ?

Piping:'*.py') ? bof.

shell.pipe(, shell.grep('*.py') ? (Needs to parse AST inside the pip argument).

Page last modified: 2024-01-18 12:48:15