source: simon willison: running python asgi apps in the browser via pyodide + a service worker

level: technical

a new approach runs python asgi web applications completely in the browser. it uses pyodide to execute python in webassembly and a service worker to intercept requests. all same-origin requests under a specific path are handled by the python app via the asgi protocol. this means no backend server is needed except for serving static files. the method works with any asgi app, as shown with a fastapi demo and the full datasette application.

the previous version, datasette lite, used web workers and intercepted navigation to fetch html from the python app. that approach had a flaw: javascript inside script tags would not run. this broke some datasette features and many plugins. the new service worker method solves this problem. it allows the python app to handle requests more like a traditional server, enabling full javascript execution.

the developer used claude opus 4.8 in claude code for web to figure out the service worker integration. the result is a general solution for running asgi apps in the browser. this could upgrade datasette lite and open the door for other python web apps to run without a backend. the technique shifts more computation to the client, reducing server costs and complexity.

why it matters: this lets data scientists deploy interactive python web tools entirely client-side, simplifying sharing and reducing infrastructure needs.


source: simon willison: running python asgi apps in the browser via pyodide + a service worker