Running Python ASGI apps in the browser via Pyodide + a service worker

Simon Willison's Blog Tools

Summary

This project demonstrates how to run Python ASGI web applications entirely in the browser using Pyodide and a service worker, intercepting requests under a path and executing them via the ASGI protocol. Examples include FastAPI and the full Datasette app.

No content available
Original Article
View Cached Full Text

Cached at: 05/30/26, 11:11 PM

# Research: Running Python ASGI apps in the browser via Pyodide + a service worker Source: [https://simonwillison.net/2026/May/30/pyodide-asgi-browser/](https://simonwillison.net/2026/May/30/pyodide-asgi-browser/) [Research](https://simonwillison.net/elsewhere/research/)[Running Python ASGI apps in the browser via Pyodide \+ a service worker](https://github.com/simonw/research/tree/main/pyodide-asgi-browser#readme)— By running Python ASGI web applications entirely in the browser using Pyodide and a dedicated service worker, this project intercepts all same\-origin requests under \`/app/\` and executes them against the Python app via the ASGI protocol—removing the need for a backend server except for static files\. The mechanism is demonstrated with both a FastAPI demo and the full Datasette app, confirming its generality across ASGI apps\. [Datasette Lite](https://lite.datasette.io/)is my version of Datasette that runs entirely in the browser using Pyodide in WebAssembly\. When I first built it[four years ago](https://simonwillison.net/2022/May/4/datasette-lite/)I used Web Workers and code that intercepts navigation operations and fetches the generated HTML by running the Python app\. This worked, but had the disadvantage that any JavaScript in`<script\>`tags would not be executed \- breaking some Datasette functionality and a whole lot of Datasette plugins\. This morning I[set Claude Opus 4\.8 the task](https://github.com/simonw/research/pull/112)\(in Claude Code for web\) of figuring out how to run Python ASGI apps in Pyodide using Service Workers instead, and it seems to work\! Here's a[basic ASGI FastCGI demo](https://simonw.github.io/research/pyodide-asgi-browser/)and here's[a demo that runs Datasette 1\.0a31](https://simonw.github.io/research/pyodide-asgi-browser/datasette.html)\. I'm still getting my head around exactly how it works, but once I've done that I plan to upgrade Datasette Lite itself\.

Similar Articles

Running Python code in a sandbox with MicroPython and WASM

Simon Willison's Blog

Simon Willison introduces micropython-wasm, an alpha package that runs Python code in a sandbox using MicroPython compiled to WebAssembly, enabling safe plugin execution within Python applications like Datasette.

OPFS + Pyodide test harness

Simon Willison's Blog

A test harness for experimenting with the Origin Private File System (OPFS) in browsers using Pyodide, built to explore persistent SQLite storage for Datasette Lite.

Publishing WASM wheels to PyPI for use with Pyodide

Simon Willison's Blog

PyPI now supports publishing WebAssembly wheels for Pyodide, allowing package maintainers to distribute their own WASM packages directly. The article demonstrates this with the luau-wasm package.