# 在浏览器中通过 Pyodide 和 Service Worker 运行 Python ASGI 应用

- 来源：Simon Willison 博客
- 发布时间：2026-05-31 05:02
- AIHOT 分数：73
- AIHOT 标记：精选
- AIHOT 链接：https://aihot.virxact.com/items/cmpsvokod04y4sluz4luwdj16
- 原文链接：https://simonwillison.net/2026/May/30/pyodide-asgi-browser

## 精选理由

Simon Willison 用 Service Worker 让 Python ASGI 在浏览器里真正跑了起来，这个技巧补上了 Datasette Lite 长期缺的 JS 执行能力，搞 Pyodide 的值得看看。

## AI 摘要

作者展示了如何在浏览器中通过 Pyodide 和 Service Worker 运行 Python ASGI 应用。此前的 Datasette Lite 使用 Web Workers，但无法执行 `<script>` 标签中的 JavaScript。新方案由 Claude Opus 4.8 协助完成开发，解决了这一问题。作者已展示了基础的 ASGI FastCGI 演示和运行 Datasette 1.0a31 的演示，并计划后续将此方法应用于升级 Datasette Lite。

## 正文

Simon Willison’s Weblog

Sponsored by: Teleport — Prevent access bottlenecks. Unify identity. Teleport replaces fragmented identity and access tooling with a single identity layer that security teams trust, and engineers want to use.

30th May 2026

Research Running Python ASGI apps in the browser via Pyodide + a service worker — 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 is my version of Datasette that runs entirely in the browser using Pyodide in WebAssembly.

When I first built it four years ago 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 (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 and here's a demo that runs Datasette 1.0a31.

I'm still getting my head around exactly how it works, but once I've done that I plan to upgrade Datasette Lite itself.

Posted 30th May 2026 at 3:34 pm

Recent articles

Publishing WASM wheels to PyPI for use with Pyodide - 13th June 2026

Claude Fable is relentlessly proactive - 11th June 2026

Initial impressions of Claude Fable 5 - 9th June 2026

This is a beat by Simon Willison, posted on 30th May 2026.

javascript 757 python 1,261 datasette 1,510 asgi 22 webassembly 126 service-workers 5 pyodide 29 datasette-lite 21 claude-code 116

Monthly briefing

Sponsor me for $10/month and get a curated email digest of the month's most important LLM developments.

Pay me to send you less!

Sponsor & subscribe

Disclosures

Colophon

©
