Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

WSRPC WebSocket RPC for tornado

Project Description

Remote Procedure call through WebSocket between browser and tornado.


  • Initiating call client function from server side.
  • Calling the server method from the client.
  • Transferring any exceptions from a client side to the server side and vise versa.
  • The frontend-library are well done for usage without any modification.
  • Fully asynchronous server-side functions.
  • Thread-based websocket handler for writing fully-synchronous code (for synchronous database drivers etc.)
  • Protected server-side methods (starts with underline never will be call from clients-side directly)
  • Asynchronous connection protocol. Server or client can call multiple methods with unpredictable ordering of answers.


Install via pip:

pip install wsrpc-tornado

Install ujson if you want:

pip install ujson

Simple usage

Add the backend side:

from time import time
## If you want write async tornado code import it
# from from wsrpc import WebSocketRoute, WebSocket, wsrpc_static
## else you should use thread-base handler
from wsrpc import WebSocketRoute, WebSocketThreaded as WebSocket, wsrpc_static

    # js static files will available as "/js/wsrpc.min.js".
    # WebSocket handler. Client will connect here.
    (r"/ws/", WebSocket),
    # Serve other static files
    (r'/(.*)', tornado.web.StaticFileHandler, {
         'path': os.path.join(project_root, 'static'),
         'default_filename': 'index.html'

# This class should be call by client.
# Connection object will be have the instance of this class when will call route-alias.
class TestRoute(WebSocketRoute):
    # This method will be executed when client will call route-alias first time.
    def init(self, **kwargs):
        # the python __init__ must be return "self". This method might return anything.
        return kwargs

    def getEpoch(self):
        # this method named by camelCase because the client can call it.
        return time()

# stateful request
# this is the route alias TestRoute as "test1"
WebSocket.ROUTES['test1'] = TestRoute

# stateless request
WebSocket.ROUTES['test2'] = lambda *a, **kw: True

# initialize ThreadPool. Needed when using WebSocketThreaded.

Add the frontend side:

<script type="text/javascript" src="/js/q.min.js"></script>
<script type="text/javascript" src="/js/wsrpc.min.js"></script>
    var url = window.location.protocol==="https:"?"wss://":"ws://" + + '/ws/';
    RPC = WSRPC(url, 5000);
    RPC.addRoute('test', function (data) { return "Test called"; });
    RPC.connect();'test1.getEpoch').then(function (data) {
    }, function (error) {
    }).done();'test2').then(function (data) { console.log(data); }).done();


Example running there demo.

Release History

Release History

History Node


History Node


History Node


History Node


This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
wsrpc_tornado-0.5.2-py2-none-any.whl (34.3 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Sep 7, 2015
wsrpc-tornado-0.5.2.tar.gz (30.9 kB) Copy SHA256 Checksum SHA256 Source Sep 7, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting