Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A bridge for Python
branch: master

renamed to to avoid standard library conflict, add…

…ed package.json to specify correct version of (0.7 changed the API)
latest commit fb62996170
evan authored

A bridge for Python

This gives Python users access to, a node.js library. This library provides simple and efficient bidirectional communication between browsers and servers over a message-oriented socket. Transport is normalized over various technologies including WebSockets, Flash sockets, and AJAX polling.


This bridge requires node.js and Install node.js and npm, then run npm install . in this directory to install the correct version of (the newer versions have changed their API).


This bridge is designed to be self-contained, so is the only file you need. A server is created by subclassing socket_io.Socket and overriding the on_connect, on_message, and/or on_disconnect methods:

import socket_io as io

class Server(io.Server):
    def on_connect(self, client):
        print client, 'connected'
        self.broadcast(str(client) + ' connected')
        print 'there are now', len(self.clients), 'clients'

    def on_message(self, client, message):
        print client, 'sent', message

    def on_disconnect(self, client):
        print client, 'disconnected'
        self.broadcast(str(client) + ' disconnected')
        print 'there are now', len(self.clients), 'clients'


The client in the browser just uses the same interface that regular clients use:

<script type="text/javascript" src="http://localhost:5000/"></script>
<script type="text/javascript">

function log(html) {
    document.body.innerHTML += html + '<br>';

var socket = new io.Socket('localhost', { port: 5000 });
socket.on('connect', function() {
socket.on('message', function(data) {
    log('message: ' + data);
socket.on('disconnect', function() {

Something went wrong with that request. Please try again.