Service Workers Enable Datasette to Run Full Python App in Browser
Original source
Running the full server-side Datasette Python app in the browser with service workers and Pyodide
Simon Willison →Datasette Lite, a reimplementation of the Python Datasette application for WebAssembly, has been completely rebuilt using service workers. The new version now functions nearly identically to the server-side original, allowing users to load SQLite databases, JSON files, CSV data, and SQL scripts directly in the browser. Through customized URLs, developers can specify which Datasette version to run from PyPI, load particular GitHub commits or branches, select from over 100 SQLite versions, and install additional plugins—all without deploying infrastructure. This creates a shareable way to demonstrate unreleased features or reproduce bugs.
The original 2022 version relied on running Datasette in a web worker with HTML injection, which prevented JavaScript execution and asset loading. The service worker approach intercepts HTTP requests for the lite.datasette.io domain, routing them to dedicated web workers via session-prefixed URLs. Each browser tab receives its own isolated Datasette instance identified by a random session ID, allowing multiple tabs to simultaneously run different plugin configurations without interference.
A new feature lets users specify SQLite versions through URL parameters. Willison created pysqlite3-wasm-wheels, containing WebAssembly-compiled Python wheels for 163 SQLite versions, enabling developers to test features or debug issues across different SQLite releases directly in their browser.
Read the full article
Continue reading at Simon Willison →This is an AI-generated summary. Read the original for the full story.