pystd
v0.3.0
Published
Python standard-library modules compiled as WebAssembly components
Downloads
410
Readme
pystd
Typed, production-oriented WebAssembly Component Model builds of selected Python standard-library modules.
Each module is an npm subpath backed by one shared componentized Python runtime. Applications that use multiple modules download and initialize CPython only once.
Requirements
- Node.js 22.12 or newer
- uv 0.11 or newer (development only)
- A runtime with WebAssembly Component Model output supported by jco
Usage
import { hashlib, itertools, math, random } from "pystd";
console.log(math.factorial(10n));
console.log(hashlib.sha256(new TextEncoder().encode("hello")).hexdigest(undefined));
console.log(itertools.combinations(new BigInt64Array([1n, 2n, 3n]), 2));
random.seed(42n);
console.log(random.random());Direct module subpaths remain available:
import { factorial, sqrt } from "pystd/math";
import { sha256 } from "pystd/hashlib";
console.log(factorial(10n));
console.log(sqrt(2));
console.log(sha256(new TextEncoder().encode("hello")).hexdigest(undefined));Additional modules use the same package and runtime, for example
import { combinations } from "pystd/itertools".
pystd/random provides CPython-compatible seeded pseudo-random generation; it
is not a cryptographic entropy source.
Portable typed subpaths also cover numeric values (statistics, fractions,
decimal), binary transforms (hmac, base64, binascii), finite collections
(bisect, heapq), text and structured data (string, textwrap, csv,
json, html, urllib-parse), and explicit dates and identifiers (datetime,
calendar, uuid). See the support matrix
for representation and host-capability boundaries.
Integer-valued math APIs use signed 64-bit bigint values at the WIT boundary. Python integers outside that range are not representable in this release.
hashlib.file_digest is exported as fileDigest, but throws NotImplementedError because arbitrary Python file-like objects cannot cross a typed WIT boundary. SHAKE hashes require an explicit digest length; fixed-size hashes require undefined.
Development
vp install
uv python install
vp run build
vp run size:snapshot
vp test
vp check
vp run docs:dev.python-version pins the CPython reference runtime to 3.14.6. Parity tests
launch it through uv run, so they do not depend on the shell's ambient
python or python3.
The adapter source is generated deterministically from api/adapters.json. Vitest file snapshots lock the generated Python glue. Builds use componentize-py 0.25.0 and jco 1.26.1, optimize for size with wasm-opt, stub unused WASI imports, and enforce an 18 MiB uncompressed shared-runtime budget. tests/fixtures/size-snapshot.json records gzip production output and prevents unnoticed size regressions.
