Python Execution Layer
Under ConstructionThe embedded Python runtime inside PySH — interactive REPL, block execution, and script mode.
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.
$ #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.
$ #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.
$ 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.