Pyodide runs Python inside WebAssembly, using Micropip to fetch packages from PyPI. When running in a browser, Micropip has two strict requirements: proper CORS headers, and support for the JSON-based Simple API (PEP 691).
Direct access to PyPI from mainland China is often unreliable, but domestic mirrors present their own challenges. Mirrors like Alibaba Cloud, Tencent Cloud, and Huawei Cloud only serve the legacy HTML index. Tsinghua’s TUNA mirror supports PEP 691, but does not send CORS headers.
As a result, there were essentially zero domestic mirrors that Micropip could pull from directly inside the browser.
To bridge this gap, I set up a Cloudflare-based mirror that adds CORS headers and handles PEP 691 lookups.
You can deploy it using either Cloudflare Workers or Cloudflare Snippets:
Workers
- Pros: Runs on the Free tier.
- Cons: Every package check counts as a Worker request, which can burn through free quotas quickly.
Snippets
- Pros: Does not count against Worker request limits, ideal for high traffic.
- Cons: Currently requires a Pro plan or above.
Code
The project is open source on GitHub: