Python Event Source Library

After looking at a lot of different technologies, it rapidly seemed obvious that HTTP 1.1’s long polling methods are what I was looking for. But when I tried to find client/server implementation, I rapidly found out websockets implementation that are über-sophisticated and with only the server-side (the client side being javascript) or other very obscure technologies I won’t list.

To help me through this whole mess of technologies, I asked my colleagues and the community on stackoverflow.

That’s how Athoune gave me a good hint about a technology I had never head about: W3C’s Eventsource.

It is basically a really simple one way communication scheme, initiated by the client, where the talking channel is from server to client. The protocol is really simple, basically it is made of several field: value, separated by two carriage return, where the field can be id, event or data.

So I took python Tornado library, and cooked a very simple, yet almost complete, client-server eventsource library in python:

It’s on my github

It comes in three components:

  • the server which opens a port and wait for new clients (GET) or for commands (POST),
  • the client which connects to the server and wait for commands, and that can be extended by giving it a callback to do “things”
  • the request client, that posts commands and values to the server, which forwards them to the client.

It’s already in Pipy and documentation is over here.

Try it, and don’t hesitate to give me feedback !