python3 in both
SDKs, including Node and browsers. It supports a subset of Python and works
with workspace files under the same permissions as shell commands. Programs
cannot access host files, host environment variables or the network.
Installation
- Python
- TypeScript
Usage
Declare aworker machine to run python3 on Monty, in worker processes Mirage starts:
- Python
- TypeScript
- YAML
Memory
Setmax_memory to limit the Python program’s memory per run, using a size
such as 64M:
MemoryError. A run also holds no more than its
workspace’s max_memory
has left, 96 MB by default.
Python compatibility
Support applies to both SDKs unless a row says otherwise. For Python syntax and standard-library coverage, see Monty’s limitations. Examples assume a writable/data mount. Mount modes and permissions still apply.
open()
Modes and modifiers are listed separately; for example, rb combines r and b.
Example: append to a workspace file
Example: append to a workspace file
Limitations
Limitations
File objects
Example: write and read lines
Example: write and read lines
Limitations
Limitations
os
The working directory and environment come from the Mirage session, not the host.
File operations
Directory operations
Metadata and links
Environment and working directory
Example: list a workspace directory
Example: list a workspace directory
Limitations
Limitations
os.path
Example: check a workspace path
Example: check a workspace path
Limitations
Limitations
pathlib
Path.cwd() and relative path resolution use the shell’s working directory.
Example: create and inspect a workspace file
Example: create and inspect a workspace file
Limitations
Limitations
sys
Mirage passes command inputs through the runtime globals.
Example: use Mirage command inputs
Example: use Mirage command inputs
Limitations
Limitations
time and datetime
The clocks start at the workspace’s system time
when it sets one, and files the program writes are stamped from the same
clock. time.monotonic() and time.perf_counter() measure elapsed time.
Example: print today's date
Example: print today's date
Limitations
Limitations
json
JSON parsing and serialization come from Monty; see its
json reference.
Example: write and read workspace JSON
Example: write and read workspace JSON
csv, tomllib and hashlib
These modules read and write workspace files through open().
Example: read a workspace CSV
Example: read a workspace CSV
Runtime globals
argv: The invocation name and arguments.stdin: The piped input.__file__: The script’s name under the starting directory.
Example: read invocation inputs
Example: read invocation inputs
Notes
- A run starts in the shell’s working directory. The script and every
relative path pass the same mount and permission checks as
cat: a rule protecting/data/job.pyrefusespython3 job.pyfrom/data. - Script arguments follow shell expansion, including globs.
- A console session takes the working directory on its first input and keeps its own after that.
raise SystemExitexits successfully.raise SystemExit("message")exits with status 1 and prints the message.
Python subset
Monty 1.4.0 implements a subset of Python, and Mirage never falls back to another interpreter. Monty maintains the details of its standard-library modules and language limitations. Those pages track upstream Monty; the integration tables above describe the version used by Mirage. Third-party imports are unavailable.Unsupported modules
Common modules unavailable in Monty 1.4.0:- Files:
glob,io,shutil,tempfile. - Networking:
http,socket,ssl,urllib. - Processes and concurrency:
concurrent.futures,multiprocessing,queue,subprocess,threading. - Data formats and archives:
array,pickle,struct,zipfile,zlib. - Numbers and hashing:
fractions,hmac,uuid. - Language and introspection:
abc,contextlib,ctypes,importlib,inspect,types,weakref. - CLI and diagnostics:
argparse,logging,traceback,unittest,warnings. - Other utilities:
enum,heapq,operator,string.