This a a great example of good work getting 'upstreamed.' The go-to solution for using requests and urllib3 in the browser had been Koen Vossen's 'pyodide-http' package, which you'd install in PyScript/Pyodide and then call 'pyodide_http.patch_all()`. It monkey-patched requests and urllib3 to use the browser API's. [1]<p>Then 'pyodide-http' got adopted into the Pyodide-included packages[2], so you didn't have to specify it for install, just import it and run patch_all().<p>And now a similar technique has been incorporated directly into urllib3. (Not a direct port - as far as I know Joe Marshall and others did a full reimplementation so that urllib3's API's would be maintained as much as possible). [2]<p>Very cool.<p>Edit: Looks like there's a note to this same effect on Seth Larson's post about urllib3's future. [3]<p>[1] <a href="https://github.com/koenvo/pyodide-http">https://github.com/koenvo/pyodide-http</a><p>[2] <a href="https://pyodide.org/en/stable/usage/packages-in-pyodide.html" rel="nofollow">https://pyodide.org/en/stable/usage/packages-in-pyodide.html</a><p>[3] <a href="https://sethmlarson.dev/urllib3-is-fundraising-for-http2-support#support-for-webassembly-and-emscripten" rel="nofollow">https://sethmlarson.dev/urllib3-is-fundraising-for-http2-sup...</a>
Incredible! Two years ago I was experimenting in porting some code at the company I was at to python in the browser (instead of QT desktop apps) and this was the biggest thing I had to work around! I had to manually monkey patch or proxy a few libraries to make them work, but I'll have to test out this update and see if everything magically works
Since this is using fetch/XHR under the hood, I guess requests from the browser are restricted only to same-origin URLs or servers responding with permissive CORS headers?
Pyodide examples using urllib3 in browser still requires using fetch, so this still requires javascript.<p>What does this practically mean?<p>Does this ever point to a future where we can use urlib3 instead of fetch?
aiohttp is still work in progress but it works with a monkey patch.
<a href="https://github.com/aio-libs/aiohttp/pull/7803">https://github.com/aio-libs/aiohttp/pull/7803</a>