Live data from Hacker News

Python HTTP library 'urllib3' now works in the browser

github.com

11–20 of 35 posts

Re: Python HTTP library 'urllib3' now works in the browser

#13

Pyodide examples using urllib3 in browser still requires using fetch, so this still requires javascript. What does this practically mean? Does this ever point to a future where we can use urlib3 instead of fetch?

Lead maintainer of urllib3 here: We're tracking all the options for how we can make the experience better for folks looking to use Python in the browser. Today our biggest blocker is that there's no socket or TLS APIs for Emscripten/WASI. If those were to become available we'd jump on them right away :) I think the biggest benefit of a foundational project like urllib3 getting browser support is that /many/ Python pr…

Thank you for your work on urllib3; I will probably never use Requests if I can help it. I'm glad that you're keeping up that "batteries included" tradition.

Re: Python HTTP library 'urllib3' now works in the browser

#15
post #14

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?

Correct! The examples we used were making requests to httpbin.org, but I also was able to query GitHub's API :)

`data = urllib3.request("GET", "https://api.github.com").json()`

Re: Python HTTP library 'urllib3' now works in the browser

#16

Pyodide examples using urllib3 in browser still requires using fetch, so this still requires javascript. What does this practically mean? Does this ever point to a future where we can use urlib3 instead of fetch?

Lead maintainer of urllib3 here: We're tracking all the options for how we can make the experience better for folks looking to use Python in the browser. Today our biggest blocker is that there's no socket or TLS APIs for Emscripten/WASI. If those were to become available we'd jump on them right away :) I think the biggest benefit of a foundational project like urllib3 getting browser support is that /many/ Python pr…

except the browser context is being sandboxed with lots of access restriction, individual profiling, geolocation reporting, device identification, and more

Big Tech does not like independent protocol operation it seems; therefore your interesting technical advance is likely to be a pawn in other, larger changes to the social contracts on the open net IMHO

Re: Python HTTP library 'urllib3' now works in the browser

#17
post #11

why would you want to run python in the browser? Anyone can ELI5?

Lots of use-cases but to name a few:

- Interactive documentation (static website)

- Jupyter Notebooks without a server, great for education (Jupyter-Lite)

- Python app alternative deployment as static webapp

Re: Python HTTP library 'urllib3' now works in the browser

#19

Earlier quoted context omitted.

Do you know if there are some plans for sockets or TLS APIs or are we far away from this?

Browsers limit the ability for these platforms to use raw sockets, there simply is no API for it. The best that can be done /today/ is to use WebSockets, which are not the same thing and can't be used for HTTP requests without the server expecting a WebSocket connection: https://github.com/emscripten-core/emscripten/issues/5196#is...

Sure, sorry if it wasn't clear from my question, it wasn't specifically about urllib3, but I meant if there are plans that browsers will make such an API available or if this is something that will never become real.
Post reply on HN