Making HTTP requests from Python code running in the browser is not straightforward. Standard networking libraries likeDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/whitphx/stlite/llms.txt
Use this file to discover all available pages before exploring further.
requests rely on system-level socket calls that do not exist in a WebAssembly sandbox. Stlite works around this by automatically patching popular libraries via pyodide-http and by exposing Pyodide’s own async HTTP primitives — so you can make network calls without changing how you normally write Python code.
Supported libraries
| Library | How it works | Notes |
|---|---|---|
requests | Patched by pyodide-http | Limited to supported classes/methods |
urllib | Patched by pyodide-http | Same limitation as requests |
urllib3 ≥ 2.2.0 | Native Pyodide emscripten backend | No patch needed |
pyodide.http.pyfetch() | Native Pyodide Fetch API wrapper | Async — use with await |
pyodide.http.open_url() | Native Pyodide synchronous fetch | Synchronous — blocks the event loop |
requests and urllib work out of the box for the methods and classes listed in the pyodide-http supported packages list.
Standard networking libraries do not work in Pyodide by default. Stlite
applies the
pyodide-http patch automatically so you don’t have to, but the
patch only covers a subset of the requests and urllib APIs.Using requests (synchronous)
Because Stlite applies the pyodide-http patch automatically, you can use requests with the familiar synchronous API — no extra setup required. Simply include requests in your requirements if it isn’t already available:
Using pyodide.http.pyfetch() (async)
pyodide.http.pyfetch() is Pyodide’s native Python wrapper around the browser’s Fetch API. It is async, which means you must await it. In Stlite, top-level await is supported, so you can use it directly in your script without wrapping it in asyncio.run().
Using pyodide.http.open_url() (synchronous)
pyodide.http.open_url() is a synchronous alternative provided by Pyodide. It returns a io.StringIO-like object you can read directly:
Limitations
CORS restrictions
HTTP requests made from inside the browser are subject to the browser’s CORS (Cross-Origin Resource Sharing) policy. Even if a request works in server-side Python, it may be blocked in Stlite if the target server does not include the appropriateAccess-Control-Allow-Origin headers.
There is no way to bypass CORS from within Stlite — this is enforced by the browser itself. If you hit a CORS error, you need either:
- A server that sets permissive CORS headers, or
- A CORS proxy that forwards requests on your behalf.
Partial API support for requests and urllib
The pyodide-http patch does not implement the full requests or urllib API surface. Features like streaming responses, session cookies, advanced authentication, and proxy support may not work. Always consult the pyodide-http supported packages documentation when you encounter unexpected behaviour.
urllib3 version requirement
urllib3 requires version 2.2.0 or later for Pyodide/emscripten compatibility. Earlier versions will not work in Stlite.