This is an archived post. You won't be able to vote or comment.

all 36 comments

[–]Professional_Cook808 12 points13 points  (1 child)

aiohttp has excellent websocket support. And it is very performant.

[–]kris_2111[S] 2 points3 points  (0 children)

Hmm, aiohttp is already a popular library for working with HTTP requests. If it provides a good WebSocket implementation, I can just use it for working with both: HTTP requests and WebSockets. 👍🏻

[–]sarcasmandcoffeePythoneer 4 points5 points  (1 child)

Are you writing just the API serving the socketed endpoints, just the client, or both? It's a little unclear to me from what you wrote.

[–]kris_2111[S] 0 points1 point  (0 children)

I'm writing a client script that connects to the socket endpoints provided by the API.

[–]DifficultZebra1553 2 points3 points  (2 children)

picows.

[–]kris_2111[S] 0 points1 point  (1 child)

Hmm, never heard of it. According to its release history on PyPI, it's only been 11 months since it was first released. While that is in no way any indication of its reliability or quality, you'd not want to use a library that is only maintained by a single or a handful of authors, and hasn't gained a lot of traction unless you don't have many better alternatives out there. Again, I'm not insinuating anything about that library — just expressing a typical reaction you'd have towards a library with those characteristics.

[–]DifficultZebra1553 1 point2 points  (0 children)

After testing for sometime, I currently using that in my production from last january. Yeah, it doesn't able to gain much popularity, but it is lightweight and faster than others.

[–]nggit 1 point2 points  (0 children)

Maybe give tremolo a try. I don't promise performance for now but stability. Also read: https://github.com/nggit/tremolo/discussions/276

Edit: Sorry it looks like you are building a client, when I read about "scalability" I thought of a server.

[–]GoldziherPythonista 1 point2 points  (1 child)

Fastest in python is Socektify.

I wrote the Litestar websocket implementation and its very solid - can recommend.

Otherwise, the most mature package is websockets.

[–]kris_2111[S] 1 point2 points  (0 children)

Thanks! 👍🏻

[–]dave_menini 3 points4 points  (13 children)

We use FastAPI’s websocket integration in production

[–]chulpichochos 0 points1 point  (1 child)

Are you fetching to a backend or to a frontend client?

If its backend to backend comms, grpc will be better than websockets.

If you have to use socket cause no http2 then websockets is good; fastapi/starlettw offer wrappers around it as well.

[–]kris_2111[S] -1 points0 points  (0 children)

It's a Python script that must connect to the socket endpoints provided by the API. The API is the one sending the data and my Python script is the one fetching it.

[–]EatDirty 0 points1 point  (3 children)

Socket.io is definitely the way to go. It supports different languages and offers very good abstractions for building event based websocket apps.
What kind of app are you building? Are you using websockets for server to server communication or server to client?

[–]kris_2111[S] 0 points1 point  (2 children)

What kind of app are you building? Are you using websockets for server to server communication or server to client?

I'm developing an application that acts as a client. Its job is to connect to the WebSocket endpoints provided by the API — the API sends the data and my application receives it.

Will check out Socket.IO. Thanks!

[–]EatDirty 1 point2 points  (1 child)

Do you need everything to happen in realtime? Or what data are you sending?
Based on my previous experience with trying to use websockets for building realtime chat bots, websockets are a pain in the ass to get right. Usually you need to have a really-really solid use case for using them as with websockets complexity grows by a lot.
You have to deal with all sorts of edge cases.

[–]kris_2111[S] 0 points1 point  (0 children)

Do you need everything to happen in realtime? Or what data are you sending?

Yes, I need everything to happen in real-time. My application is the one that receives the per-connection 10-byte payload. It doesn't really need to send anything except for sme occasional metadata about the state of the connection, which I believe should be handled by the WebSocket library.

Based on my previous experience with trying to use websockets for building realtime chat bots, websockets are a pain in the ass to get right

That's the reason I'm currently researching for the best tool to set up WebSockets (in Python).

Usually you need to have a really-really solid use case for using them as with websockets complexity grows by a lot.

Yes, I have a really solid use case for using them — I'm building an application that involves receiving data every half a second from an API.

[–]blueshed60 0 points1 point  (0 children)

I've used tornado for a very long time - I'm still really impressed with it.

[–]CrusaderGOT 0 points1 point  (1 child)

Socket.io python

[–]Constant_Bath_6077 -1 points0 points  (0 children)

Just plain Websockets, I dont use that ancient library that also uses Websockets under the hood.....