modules
Run python show_modules.py to list bundled modules.
Additional standard-library modules
Run python py2scratch.py examples/stdlib_demo.py stdlib_demo.sb3, then load the generated project in Scratch and click the green flag. The sample uses random, fractions, io, and json to print {"average": "16/3", "picks": [6, 3, 7]}.
| Module | Available APIs |
|---|---|
random |
Mersenne Twister with CPython-compatible integer seeding and state, random bits and bytes, randrange, randint, choice, choices, sample, shuffle, and selected distributions |
fractions |
Fraction from integers, floats, and strings, rational arithmetic and comparisons, rounding, and limit_denominator |
json |
dumps, loads, dump, load, encoder and decoder classes, indentation, sorting, parsing hooks, and decode error positions |
io |
StringIO, BytesIO, seeking, truncation, line reads and writes, and context managers |
base64 |
Base16, Base32, Base32hex, Base64, URL-safe Base64, and stream encoding and decoding |
binascii |
Hex conversions, Base64 conversion, crc32, and crc_hqx |
copy |
Shallow and deep copies of containers and user instances, including cycles, shared references, and custom copy hooks |
queue |
FIFO, LIFO, priority, and simple queues for immediate operations in the Scratch interpreter |
colorsys |
RGB conversions with HSV, HLS, and YIQ |
keyword |
Python 3.12 keyword and soft-keyword checks |
Strings and bytes support ASCII, Latin-1, UTF-8, and UTF-16 codecs. Queue operations that would have to wait on another thread raise immediately. Fraction values support numeric protocols in expressions. The runtime uses object identity for custom objects looked up as dictionary keys.
Expanded module coverage
This release covers selected APIs from 64 of the 212 public top-level modules in Python 3.12, or 30.2% by module count. Each module has a working example in examples/showcase.py. Coverage counts modules with tested APIs. The implementation of individual modules varies by API.
| Module | Available APIs |
|---|---|
array |
Typed numeric and Unicode arrays, list operations, byte conversion, and file-like streams |
calendar |
Leap years, weekdays, month ranges and grids, text calendars, and timegm |
codecs |
Codec lookup and registration, Unicode encodings, selected binary transforms, and buffered incremental codecs |
configparser |
Read and write in-memory INI data, section proxies, typed getters, and basic and extended interpolation |
contextlib |
contextmanager, ExitStack, ContextDecorator, closing, suppress, and nullcontext |
csv |
Readers and writers, dictionary rows, dialect settings, escaping, quoted multiline fields, and field size limits |
datetime |
Dates, times, durations, fixed-offset timezones, ISO parsing and formatting, arithmetic, and selected strftime fields |
decimal |
Decimal construction, arithmetic, comparisons, context precision, rounding, traps for selected signals, and quantization |
difflib |
SequenceMatcher, matching blocks and opcodes, close matches, unified diffs, and restoring lines from deltas |
fnmatch |
Wildcard, character-range, and negated-character matching, filtering, and regex translation |
getopt |
Short and long options, bundled short options, and GNU-style operand handling |
graphlib |
Incremental and static topological sorting, predecessor tracking, and cycle reporting |
html |
Escaping, named HTML5 entities, and numeric references |
ntpath |
Lexical Windows paths, drive/root splitting, normalization, joins, and relative and common paths |
pathlib |
Pure POSIX and Windows paths, properties, pattern matching, relative paths, suffix replacement, and file URIs |
posixpath |
Lexical POSIX paths, joining, drive/root/extension splitting, normalization, and relative and common paths |
pprint |
Pretty-printing lists and mappings, width, depth, indentation, key ordering, and recursion detection |
quopri |
Quoted-printable bytes and file-like streams, with header mode |
re |
String patterns, matching and substitution, groups and backreferences, character classes, lookahead, and common flags |
shlex |
Shell-style tokenization, quoting, joining, and punctuation tokens |
struct |
Standard and LP64 little-endian native layouts, signed and unsigned fields, byte strings, IEEE floats, and streaming unpack |
textwrap |
Wrap, fill, shorten, dedent, indent, and TextWrapper options |
types |
SimpleNamespace, live read-only mappings, resolve_bases, generic aliases, and union type metadata |
argparse |
Explicit argument lists, typed options, positional arguments, defaults, choices, common actions, groups, short-option clusters, and contextual usage |
copyreg |
Reduction registration integrated with copy and deepcopy, extension registration |
gzip |
In-memory compression and decompression, gzip members and checksum verification |
inspect |
Type predicates, member lookup, annotations, MRO, signatures and argument binding for compiled Python functions and methods |
ipaddress |
IPv4/IPv6 addresses, network prefixes, packed bytes, interfaces, subnet iteration and merging address ranges |
logging |
Loggers, levels, filters, stream handlers, adapters, and percent-style formatters |
reprlib |
Bounded recursive representations, customizable length/depth, and recursion-safe representation decorators |
stat |
File-kind constants, permission and mode masks, and filemode formatting |
stringprep |
RFC 3454 character tables, B.2 and B.3 mapping |
token |
Python 3.12 token constants, token names, and exact operator types |
tokenize |
Tokenize ordinary Python source lines and in-memory byte streams; token coordinates, indentation, comments, strings, numbers, and untokenization |
unicodedata |
Unicode property and decomposition tables, digit/decimal/numeric values, NFC/NFD/NFKC/NFKD normalization |
unittest |
Test cases and suites, assertions, exception contexts, loading test methods, skip/expected-failure decorators, and result collection |
uuid |
UUID parsing, integer and byte transformations, field access, namespace constants, and version/variant bits |
warnings |
Warning categories, filters, explicit warnings, warning recording and suppression |
zlib |
Adler-32 and CRC-32, stored and fixed-Huffman compression, stored/fixed/dynamic-Huffman decompression, raw/zlib/gzip streams |
The path and config adapters work with strings and file-like streams. Concrete POSIX paths and file-backed operations use a project-local virtual filesystem. Host filesystems, host timezones, non-C locale formatting, and subprocesses remain outside the runtime. The regex engine accepts string patterns and a subset of Python regex syntax. Lookbehind, atomic groups, and bytes patterns remain unsupported. Struct’s native formats use a fixed little-endian LP64 layout. Use explicit < or > formats for portable numeric layouts.
The adapters are designed for portable computation. Complex numbers use Scratch double arithmetic and are implemented as user objects, with integer exponents supported. Generic type annotations execute or preserve their string representation with from __future__ import annotations. Resolving string annotations through get_type_hints and inspect.get_annotations(eval_str=True) requires explicit name mappings. Runtime generic type enforcement, arbitrary metaclasses, type-parameter declaration syntax, and frozen/slot/hash dataclass options need more runtime work. Namedtuple fields are immutable.
Timing uses Scratch's clock, and the monotonic timer is relative to the Scratch session. timeit takes callables. The portable timezone is UTC; actual host timezone and process CPU timers are unavailable. argparse takes explicit argument lists. Logging and test output can be directed into memory streams. Stack-derived warning locations, full source-text introspection, test discovery on the host disk, and native tracebacks are outside the supported APIs. The tokenizer covers ordinary source tokens, with f-string token internals unsupported. UUID generation using host entropy or hardware identifiers is unavailable. The compressor supports portable in-memory streams, with a fixed-Huffman encoder and stored blocks; compression ratios can differ from CPython. Streaming compression objects, preset dictionaries, and gzip files are available for the virtual filesystem. Compressed bytes need not match the host zlib encoder byte-for-byte. The Unicode database is generated from the compiler's host Python version.