ADR 023. v0.10 roadmap: the browser gets the CPython-facing build¶
- Status: Accepted (2026-10-26).
- Decider: project maintainers
- Branches from: ADR 021 (v0.9, implemented in 0.9.0), whose §3 named a browser-first cycle as the likely next theme; ADR 006 for the
jsbridge; ADR 022 for the embedding API and its open questions. - Consequences: moves the browser build from the
nanoprofile tofull, so the browser behaves like the native build and most "(browser)" rows leave the differences page, at a stated size cost; ships one wasm module in the npm package; bringsasyncioto the browser over the JavaScript event loop, without asyncify; answers ADR 022's questions on interrupts and keyword arguments.nanoremains the byte-exact strangler gate on native.
1. Context¶
0.9.0 is out on PyPI, npm and Homebrew (2026-10-25). It made the native build follow CPython where scripts noticed: insertion-ordered dicts, keyword arguments on built-in methods, C3 method order, slice(), ModuleNotFoundError, annotations evaluated at run time. All of it landed on full, because nano must stay byte-exact against MicroPython.
The browser build is nano, so it got none of it. The differences page now splits along that line: most rows marked "(browser)" describe behaviour the native build already fixed. A user who tries the playground and then installs petitpy with pip meets two different Pythons.
The browser build was nano because of integers: without MPZ, full on wasm32 hit the bignum wall. 0.9 shipped MPZ in the browser build (ADR 021 §7), which removes that reason. A probe on 2026-10-25 confirms it: full builds for wasm32-wasi. Judged against the full arm's goldens, it passes the corpus except the native full known-fails, struct1_intbig (wasm32's 32-bit word, already a wasm known-fail) and the io tests where seek() returns 0. A script exercising dict order, split(sep=), 2**100, slice(), __mro__, json and ModuleNotFoundError prints what CPython prints.
The cost, measured on the shipping recipe (ReleaseSmall, frozen stdlib, js module, wasm-opt -Oz): web/petitpy.wasm grows by about 10% raw and 8.5% gzipped. That is the main trade this ADR asks to take.
Other browser items are on record. The npm package ships two wasm modules: petitpy.wasm, run once per program, and petitpy-embed.wasm, the long-lived reactor module behind petitpy/embed (ADR 022 §6 asked when to merge them). There is no asyncio: coroutines run, with no loop to drive them. The js bridge is synchronous, so a page cannot await a fetch (ADR 006 deferred it).
No issue has been filed on the public tracker yet, so ADR 021 §2.1's rule (reports reorder the plan) has had nothing to act on. It still holds for v0.10.
2. Decision¶
v0.10 is the browser-first cycle, in this order.
2.1 The browser build moves to full¶
The browser build (make web, web/petitpy.wasm, the npm package, the playground) and the embedding wasm module are built with -Dconfig=full. make wasm-check judges the corpus against the full arm's goldens and baseline, plus a list of wasm-only failures; corpus/wasm-mpz-goldens.txt is no longer needed. The io seek failures are fixed. struct1_intbig stays listed until the 32-bit word stores large values byte-wise, as MicroPython's 32-bit ports do.
The parts of full that mean nothing in a browser (subprocess, sockets, the process environment) are left out of the browser build where that is a configuration switch. The size is then measured again, with 8.5% gzipped as its ceiling.
Each "(browser)" row of the differences page is checked against the new build, with an integration case, and removed or narrowed. The page then describes one Python with a few platform rows (no files or os in the browser).
2.2 One wasm module in the npm package¶
loadPetitpy, the run-a-program API of the npm package, moves onto the reactor module, so the package ships one wasm module and both APIs share it. The reactor module first gains what petitpy.wasm has today (the js module, the frozen stdlib). The playground and demos move with it. The JavaScript API stays the same; if it cannot, the change is stated in the changelog.
2.3 asyncio in the browser, over the JavaScript event loop¶
MicroPython's asyncio (the _asyncio C module and its Python package, already in vendor) is enabled on the browser build, with a loop that returns to JavaScript between steps: asyncio.run() runs the ready tasks, then schedules its next step from JavaScript (setTimeout, or a resolved Promise). A JavaScript Promise becomes awaitable from Python: awaiting it parks the task. When the Promise resolves, the loop resumes through the callback path the js bridge already has.
This needs no asyncify and no stack switching, so it keeps ADR 006's synchronous ABI and its size. Code that blocks without awaiting still blocks the page, as today. The size cost is measured and stated; the pure-Python parts can stay out of the frozen stdlib and load on import if that matters.
The native build gets asyncio in the same cycle, on vendor's own loop over select.poll, which full already has. Both builds share the Python package; only the loop's wait step differs.
2.4 Two embedding questions¶
Two of the questions in ADR 022 §6 also serve the browser work:
ppy_interrupt(interp): raisesKeyboardInterruptat the interpreter's next check, callable from another thread without the lock. On the browser, the same mechanism stops a runaway program in the playground from a worker.- Keyword arguments for host functions, which the Promise bridge of §2.3 and the JavaScript wrapper of
petitpy/embedwould pass through.
A shared library and parallel interpreters stay open (§5).
2.5 What stays fixed¶
nanobyte-exact against MicroPython atMICROPY_REV, on the whole corpus, on native. It stops being a shipped build and remains the strangler gate.- The strict bidirectional gates, and CI passing on a fresh checkout.
- The full arm's corpus baseline only shrinks; the wasm baseline starts from the full one plus the 32-bit-word tests, and only shrinks after.
- The size watch on wasm: beyond §2.1's cost, any v0.10 change that grows the browser build by more than 2% states the cost in the commit message.
3. Alternatives considered¶
Keep the browser on nano and port the CPython-facing changes there. Each change breaks the byte-exact gate on nano, or needs a third profile between nano and full. Both cost more than the size difference.
Ship both, nano as a small browser build and full as the default. Twice the gates, the goldens and the docs, for a 15 KB gzipped difference. Rejected unless users ask for the small build; see §6.
CPython exception text and tracebacks with line numbers. These are now the largest rows left on the differences page, on both builds. Exception text changes every golden that prints an exception, and line numbers need source-line emission (MICROPY_ENABLE_SOURCE_LINE), which costs bytecode size. A good theme for the cycle after, with its own ADR; moving the browser to full first means that work is done once, on one profile.
asyncify or JSPI for await. asyncify adds 30-50% to the wasm (ADR 006 §2); JSPI (JavaScript Promise Integration) avoids that but is not yet in every browser. The loop in §2.3 needs neither, at the price of no blocking calls inside a coroutine.
Parallel interpreters. Needs the pending exception out of its global (ADR 022 §6), a large change in the interpreter loop. No host has asked for it.
4. Sequencing¶
fullon wasm (§2.1): the build switch, the new wasm baseline, theiofixes, the trimmed configuration and the size. Then the differences page.- One wasm module (§2.2), on top of 1.
asyncio(§2.3), on top of 1, in parallel with 2.ppy_interruptand keyword arguments (§2.4), in parallel with 3.- Release 0.10.0 when 1 and 2 have landed; 3 (on both builds) and 4 ship if ready, or move to the next cycle with a note here.
5. Out of scope for v0.10¶
- CPython exception text and traceback line numbers (§3).
- Real threads, parallel interpreters, a shared library.
- Unicode case mapping and
unicodedata, complex numbers, implicit exception chaining (__context__). - wasm64, still gated on the Zig toolchain.
- CPython C-API extension loading.
6. Open questions¶
- Decided (2026-10-26):
nanocan still be built for wasm, as a size option. - Is the trimmed browser
fullsmall enough that §2.1's cost needs no more work, or should the frozen stdlib load lazily? The trimmed build is measured first. An amendment here records the answer.
7. Consequences¶
Wins: one Python across the playground, npm and pip install; the differences page shrinks to the rows that are true everywhere; the npm package gets lighter by one wasm module; browser code can await JavaScript, and native code gets asyncio with the same package.
Costs: the browser build grows by 4.1% gzipped (§8). The wasm baseline is rebuilt once. nano is no longer what any user runs, so the strangler check becomes the profile's whole purpose.
Preserved: the strangler invariant on native, the gate discipline, the synchronous js ABI.
8. Amendment (2026-10-26): the trimmed browser build, measured¶
The build already left os, time, socket, select, signal, pwd, grp and subprocess out of every wasm target. Five frozen stdlib modules import one of them (subprocess, shutil, pathlib, uuid, datetime), so they could never load in a browser. The wasm builds now freeze a bundle without them.
Trimmed that way, web/petitpy.wasm grows by 7% raw and 4.1% gzipped over the 0.9 nano build, and the embedding module by 7.3% raw and 4.4% gzipped: half the probe's figure. At that cost, loading the frozen stdlib lazily would save little size, and §6 keeps it as a question of start-up time, for measurements in a browser.
datetime in the browser waits on a time module for wasm.
9. See also¶
- ADR 021: the v0.9 roadmap, and §7 on MPZ in the browser.
- ADR 006: the
jsbridge and the deferredawait. - ADR 012: the
nanoandfullprofiles. - ADR 022: the embedding API.
- Differences from CPython.