Skip to content

PyWeb 0.3.0

Choose a tag to compare

@MaanavKrishna MaanavKrishna released this 03 Oct 06:26
· 102 commits to main since this release
15d3a36

Faster pages that feel like an app, apps that span several files, and
tools for editors, the browser and AI assistants.

Added

  • Hydration. Pages now adopt the server-rendered DOM instead of
    rebuilding it: nodes are kept, focus and text typed before the script
    loads survive, and typed values reach their variables. When the server
    HTML doesn't match, the page falls back to a client render and logs
    a warning. The page root carries data-pw-mode="hydrated" or
    "rendered".
  • Live updates. publish(name, data) in server code pushes to every
    page that called subscribe(channel_feed, handler), over Server-Sent
    Events with a polling fallback. Feeds come from channel(name) while
    rendering: signed, expiring, and positioned so no message published
    after the render is missed. pyweb dev, pyweb serve and the ASGI
    adapter stream; realtime.use_bus() shares the bus (e.g. Redis)
    between processes. The chat example uses it instead of polling.
  • Multi-file apps. from widgets import Card, save, COLOR imports
    components, @server functions and constants from widgets.pyweb (or
    ui/cards.pyweb as ui.cards). Each file keeps its own names in the
    generated JavaScript, imported files run as real modules on the
    server, pyweb build copies them into dist/, and errors name the
    file they're in. Pages stay in the app file; circular imports and
    duplicate server-function names are compile errors.
  • Editor support. pyweb lsp is a language server (stdio, standard
    library only): compile errors and security warnings as you type,
    hover showing where each name runs and why, completion for components,
    props and tags, go to definition across files, and an outline. The new
    VS Code extension (editors/vscode) adds highlighting and snippets and
    starts it; releases attach a .vsix. Setup for Neovim and Helix is in
    the command-line docs.
  • Playground on the website: edit an app and run it in the browser,
    with the real compiler, server rendering, @server functions,
    sessions and live updates running on Pyodide. Shows the compiled
    JavaScript and what runs where, reports errors with a fix, and shares
    code as links.
  • MCP tools pyweb_screenshot (open a page in headless Chromium,
    run click/fill/press steps, get a screenshot, the page text, console
    errors and hydration status) and pyweb_test (run the app's pytest
    tests and report failures). New apps include a starter test_app.py.
  • python -m pyweb.bench --max-ssr-ms N --max-compile-ms N fails when
    a benchmark exceeds its budget; CI runs it.

Removed

  • The old pyweb.lsp helper functions (complete, DocumentState,
    complete_*, diagnostics_for_compile_error, hover(compiled, name),
    boundary_lens); they described an earlier API and no editor used them.

Changed

  • import pyweb no longer needs the sqlite3 module (it's imported when
    a SQLite database is opened), and password hashing falls back to a
    pure-Python PBKDF2 on Pythons without OpenSSL. Both make PyWeb run on
    Pyodide.
  • /__pyweb/events and /__pyweb/poll require a signed ?feed=; the
    unauthenticated ?channel= form is gone, so channels are no longer
    readable by anyone who guesses a name.
  • Server rendering caches compiled template expressions; rendering a
    page is about twice as fast.
  • Generated page modules pass element children as a function and wrap
    every child in a call ($t, $dyn), so nodes are created in document
    order.