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

- 来源：Simon Willison 博客
- 作者：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。

## 正文

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

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.

Tags: javascript, python, datasette, asgi, service-workers, pyodide, datasette-lite, claude-code
