Emscripten-Shell / Py-Xterm

Published January 19, 2023

Tags: pyscript python pyodide emscripten EmShell

plugins = ['build/pyxterm.min.js']

This is a (very rough) demo of a multilayered project called Emscripten Shell (EmShell for short)

The EmShell Logo

Currently, the project encompasses three different levels of usage (which really should be three separate projects):

  • The Emscripten-Shell itself, which is written in TypeScript/JavaScript and can be used with any program that uses the Emscripten Filesystem using the custom <x-term> element.
  • py-xterm, an enhancement of the Emscripten Shell for Pyodide that adds additional Python-specific functionality, including the python and pip commands, using the <py-xterm> element
  • A plugin for PyScript that adds the <py-xterm> element to a page using PyScript.

As my primary pursuit is PyScript, this has full pyscript integration. Trying typing python and using display("Hello world", target="target") in the included REPL - you'll see that the in-terminal REPL has full PyScript functionality.

This project is in such early days, I hesitate to even call it an Alpha version. The shell is really more a series of hard-coded commands - things like line history, piping and redirect, variable expansion, arrow keys... none of that's here. There's also some slight weirdness going on with the REPL and imports... not sure what's happening there.

In the long term, I think it would be interesting to try compiling an existing POSIX shell like mrsh with Emscripten and figuring out how to integrate that with other Emscripten-built programs.

See the usage section on GitHub if you want to try out this early version.


  • Jan 19, 2023 Initial post, with cd, clear, help, ls, pip, pwd, and python commands
  • Jan 19, 2023 Added rudimentary touch, cat commands
  • Jan 19, 2023 Added -m option for python command