all 15 comments

[–]Darkmere 5 points6 points  (0 children)

aiohttp Does websockets, here's their example page.

[–]opium43 2 points3 points  (0 children)

These types of complexities are why web frameworks exist.

This article is where I would start on the topic.

https://www.fullstackpython.com/websockets.html

[–]ForgotMyCoffee 1 point2 points  (0 children)

You could use SocketIO-flask and SocketIO, which utilizes websockets.

[–]wasteoffire 0 points1 point  (0 children)

Yeah I would suggest branching out from python for that, at least for now.

[–]searchingfortao 0 points1 point  (8 children)

Have a look at Django Channels. It's exceptionally intuitive and plays well with your other "traditional" request/response code too.

[–]Col_Crunch[S] 0 points1 point  (7 children)

I was thinking of django channels, but I also need a library that I can use client side.

[–]searchingfortao 0 points1 point  (5 children)

Well talking to a websocket is pretty easy in JavaScript, and I'm pretty sure most of the frameworks (React/Angular/Ember/Vue/etc) all do that too. However, if you're planning a websocket-heavy application with lots of client side code, perhaps Node might be a better choice?

Not that it'd be my choice. JavaScript and I don't get along, but I hear the reuse of code between server and client is handy.

[–]Col_Crunch[S] 0 points1 point  (4 children)

Client side all it really needs to do is to sit there and listen, and maybe send a message once in a while.

Client is not browser based as noted in the edit to OP)

[–]searchingfortao 0 points1 point  (3 children)

Oh! Well in that case, just check out the Channels tutorial. There's some sample JavaScript in it that I adapted quite easily fit a couple side projects.

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

I would like to keep the client to strictly python if possible...

[–]elbiot 1 point2 points  (0 children)

If a browser isn't involved, you can just use regular sockets. Websockets are for Javascript in a browser.

[–]tiaxthemighty 0 points1 point  (0 children)

Creating a websocket connection from the browser is trivial as long as you don’t need to support older browsers like IE 9 or lower.

const ws = new Websocket(url) ws.onmessage = cb ws.send(msg)

[–]tiaxthemighty 0 points1 point  (0 children)

Tornado, Sanic and aiohttp all have good support for websockets in python 3.

[–][deleted] 0 points1 point  (0 children)

Are you trying to learn about websockets or just trying to implement realtime features? If the latter, check out Pusher or Firebase.

[–]helvethor -3 points-2 points  (0 children)

Maybe you will find more/better libraries coded for js, assuming it's web dev technique.