25th
python-websocket - a WebSocket client library for Python
So, have you heard about this WebSocket thing? Apparently it’s the new hotness in web development. It gives you “TCP-like” networking capabilities from within your browser, through a JavaScript API. But sometimes you just want to write a desktop application. Unfortunately, the selection of WebSocket client libraries is quite scarce, and not all of them are compatible with the server implementations since the WebSocket spec has yet to stabilize. I needed a client library for Python, so I wrote one. The protocol itself is quite simple: just a HTTP handshake (with optional cookies), followed by a thin layer on top of TCP. The code is currently lacking proper testing, so I wouldn’t recommend using it for production stuff.
Here’s how to use it:
def my_msg_handler(msg):
print 'Got "%s"!' % msg
socket = WebSocket('ws://example.com/demo', onmessage=my_msg_handler)
socket.onopen = lambda: socket.send('Hello world!')
try:
asyncore.loop()
except KeyboardInterrupt:
socket.close()
Pretty sweet. It tries to mimick the browser API to a T. Now, onto the good stuff:
Source and docs: http://github.com/mtah/python-websocket
License: GPLv3