Skip to content

Module support

pystd includes standard-library APIs that can be represented by a stable, typed WIT boundary and behave consistently in browsers, Node.js, and other WebAssembly hosts. “All modules that make sense” means all modules meeting those constraints, not every module shipped with desktop CPython.

Support matrix

GroupStatusExamplesPortability notes
Pure numeric and deterministic algorithmsSupported and expandingmath, random, statistics, fractions, decimalStrong fit when values have an unambiguous typed representation.
Hashing and binary transformsSupported and expandinghashlib, hmac, base64, binasciiCryptographic entropy and unavailable native backends remain excluded.
Finite collection algorithmsSupported and expandingitertools, bisect, heapqAPIs accepting arbitrary Python iterators, callbacks, or objects need a narrower typed surface.
Text and structured dataSupported and expandingstring, textwrap, csv, json, html, urllib.parsePure transformations are supported; file-oriented convenience APIs are excluded.
Date and identifiersSupported and expandingdatetime, calendar, deterministic uuid operationsExplicit values are supported; ambient local time, locale, timezone databases, and entropy are excluded.
Compression and archivesCandidatezlib, gzip, bz2, lzma, zipfile, tarfileIn-memory APIs fit when the native codec is available; filesystem APIs do not.
Filesystem and process integrationExcluded from the portable packageos, pathlib, tempfile, shutil, subprocess, multiprocessingThese require host-specific WASI capabilities and cannot behave uniformly in a browser.
Networking and servicesExcluded from the portable packagesocket, ssl, http, ftplib, smtplib, urllib.requestNetworking must be supplied by the JavaScript host, with a separate capability-oriented API.
Runtime, compiler, and debugging internalsExcludedsys, gc, inspect, importlib, ast, dis, trace, pdbThey expose the embedded interpreter rather than a reusable standard-library operation.
UI, platform, and database bindingsExcludedtkinter, curses, winreg, sqlite3, dbmThey depend on platform libraries, persistent storage, or UI systems absent from the portable runtime.

Selection rules

A module is included when its useful core can be kept small, represented with typed values, and verified against pinned CPython without filesystem, network, subprocess, locale, or ambient OS entropy. Narrow typed subsets are preferred over pretending that arbitrary Python objects cross the component boundary.

The portable surface now includes:

  • numeric algorithms: math, random, statistics, fractions, and decimal;
  • hashing and binary transforms: hashlib, hmac, base64, and binascii;
  • finite collections: itertools, bisect, and heapq;
  • text and structured data: string, textwrap, csv, json, html, and urllib.parse;
  • explicit dates and identifiers: datetime, calendar, and deterministic uuid operations.

Each module has a typed subpath under pystd/<module>. urllib.parse uses the npm-safe subpath pystd/urllib-parse and root namespace urllibParse.

Representation boundaries

fractions and decimal use canonical strings so values do not lose precision at the JavaScript boundary. Finite integer collection APIs use signed 64-bit bigint typed arrays. json.loads and json.dumps convert between JSON text and JavaScript JSON values; Python-specific object hooks are not exposed. Date/time APIs accept ISO 8601 strings or explicit Unix timestamps and interpret naive datetime timestamps as UTC.

uuid3 and uuid5 are supported because their output is deterministic. Random UUID construction is excluded until the host provides explicit secure entropy and clock capabilities.

Randomness

pystd/random implements CPython's deterministic random.Random behavior for reproducible simulations and tests. Explicit integer seeds match CPython. The portable runtime deliberately does not expose ambient OS entropy, so SystemRandom and secrets are not provided and the omitted-seed convenience uses the current JavaScript time. This module must not be used for security.