AI产品精选72°

用 Pyodide + Service Worker 在浏览器中运行 Python ASGI 应用

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

精选理由

解决了浏览器中运行 Python Web 应用时 JavaScript 无法执行的痛点,做 Datasette 插件或 Pyodide 相关项目的开发者可以直接试用新 demo。

AI 摘要

Simon Willison 通过 Claude Opus 4.8 的帮助,成功让 Python ASGI 应用(如 Datasette)在浏览器中通过 Pyodide 和 Service Worker 运行。此前使用 Web Worker 的方案无法执行 HTML 中的 <script> 标签,限制了插件功能。新方案利用 Service Worker 拦截网络请求,使得 JavaScript 代码能够正常执行,从而支持更多 Datasette 插件。目前已有基础 ASGI FastCGI 演示和 Datasette 1.0a31 演示,未来将升级 Datasette Lite。

原文 · Simon Willison’s Weblog

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

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 &lt;script&gt; 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

用 Pyodide + Service Worker 在浏览器中运行 Python ASGI 应用 · AI 热点