Standard library
A permitted subset, not a sandboxed copy of the whole thing. A module is here because it is useful for the kind of code this runtime exists to run, and because it can be implemented without reaching outside the sandbox.
| Module | Notes |
|---|---|
json |
dumps, loads, and the usual options |
re |
pattern matching, substitution, splitting |
math |
the numeric functions and constants |
datetime |
date, time, datetime, timedelta, driven by the host's TimeProvider |
collections |
Counter, defaultdict, deque, OrderedDict, namedtuple |
dataclasses |
@dataclass and field |
io |
in-memory streams |
os, os.path |
over the virtual filesystem |
pathlib |
over the same filesystem |
glob, fnmatch |
pattern matching against the same filesystem |
sys |
argv, stdin, stdout, stderr, exit, platform, version |
unicodedata |
character properties |
asyncio |
the subset upstream supports |
Filesystem-backed modules
open, os, os.path, pathlib, glob and fnmatch all go through the host's IFileSystem.
When the joined Computerwelt package is used, that is the same filesystem the shell sees, so a
file a command wrote is a file the program opens, under the same quotas and the same POSIX paths.
With no filesystem configured, these raise OSError rather than failing in a way the program cannot
name.
import os
for name in sorted(os.listdir('/data')):
with open(f'/data/{name}') as handle:
print(name, len(handle.read()))
os.walk and os.scandir are among the things this port adds beyond upstream Monty, along with
glob, fnmatch, io and sys.argv. They live in their own fixture folder in the repository
precisely so that a reader can tell a port decision from the upstream specification.
Reporting what is missing
import of a module that is not here raises ImportError naming it. As with the language subset,
that is a message a model can act on.
Read next
- The language subset — what the parser accepts.
- Host libraries — adding a module of your own.
- The virtual filesystem — what
openreaches.