Shell

PytoRuntime includes a shell that can be executed through from run(_:with:enableBreakpoints:) or run_shell().

It provides access to various UNIX commands from ios_system, which is used in iOS / iPadOS apps.

These commands are embedded in the app and are executed in the same process and can be executed with system() and Popen.

Input

The shell uses uses the Python readline module compiled with BSD libedit for input, which provides code completion and word navigation. The history is saved in ~/Documents/.shell_history and the libedit configuration file can be created in ~/Documents/.editrc.

Commands

Type help in the shell to see a list of available commands.

Scripts installed from PyPI or packages embedded in-app will also be recognized by the shell. These scripts are installed in ~/Documents/.local/bin for user installed scripts and [...]/site-packages/bin for bundled packages. If you want to run a module that has no entrypoint specified in pyproject.toml, you can always run the python interpreter: $ python -m my_module.

Operators

The shell supports operator for redirecting output and input.

Write to file:

$ find . -name "*.py" > scripts.txt

Append to file:

$ date >> history.txt

Pass file as input:

$ python < my_script.py
Hello World!

Pass output from a command to another command as input.

$ echo 'print("Hello World!")' | python
Hello World!

Environment

Environment variables can bet set with export, and read like any other shell.

$ export FOO=BAR
$ echo $FOO
BAR

You can read all the current environment by running export or env without arguments.