Python Execution Layer

Under Construction

The embedded Python runtime inside PySH — interactive REPL, block execution, and script mode.

Note: The Python Execution Layer is one of the core differentiators of PySH. It is not a subprocess call to the system Python — it is an embedded runtime with shared state and shell environment access.

Overview

The PySH Python Command Execution Layer (PCEL) is an embedded Python runtime that runs inside the PySH shell process. It shares the shell's environment, working directory, and plugin state. Variables created in PCEL persist across #py invocations within the same session.

Interactive mode — #py

Enter #py at the PySH prompt to switch to interactive Python mode. This gives you a standard Python REPL with additional PySH context injected into the namespace.

Interactive Python mode

$ #py

PySH Python Command Execution Layer

Python 3.13.5


$ import os

$ os.getcwd()

'/home/user/projects'


$ x = [1, 2, 3]

$ sum(x)

6

Block mode — #pyblock

Use #pyblock to enter a multi-line Python block. The block is collected until you submit it with an empty line. Useful for functions, classes, or multi-statement logic.

Block mode

$ #pyblock

... def greet(name):

... return f"Hello, {name}!"

...


$ greet("PySH")

'Hello, PySH!'

Script mode

Run a Python script directly from the PySH shell. The script runs in the PCEL context, with access to the shell environment.

Run a Python script

$ pysh run my_automation.py

Running my_automation.py ...

Done.

State persistence

  • Variables defined in #py persist for the duration of the PySH session.
  • Modules imported in #py remain available in subsequent #py entries.
  • The PCEL namespace is reset when PySH exits.
  • Use scripts or plugins for logic that must survive across sessions.