[IPython-dev] make ipython work over web

Ondrej Certik ondrej at certik.cz
Sat Mar 27 14:27:34 EDT 2010

On Sat, Mar 27, 2010 at 10:57 AM, Brian Granger <ellisonbg at gmail.com> wrote:
> Ondrej,
>> I would like both the browser and the command line to use the exact
>> same API, so that I can easily test the server part using unittests.
> I am not quite sure I understand what you mean by the "same API".  Do you mean
> the wire level JSON messages?  The programatic API (classes+methods,
> etc), or something else.
> I don't that what you want is possible actually though.  The reason is
> that a browser/server architecture is pure request/reply (1 way only).
>  You can fake server->browser requests but it still required quite a
> bit of magic on server and browser sides.
> With our 0MQ based kernel, the kernel opens two types of 0MQ sockets:
> 1. XREP.  This is a request reply socket that multiple clients can use
> to interact with the kernel in a traditional request/reply manner.
> This is how a client can execute code, do tab completion.
> 2. PUB.  This is a publication socket.  It is one way outbound from
> the server to the client.  You can think of a PUB socket as a radio
> transmission.  The client subscribes to topics on the socket (using a
> SUB socket) and gets the messages that matches the subscribed topics.
> We use the PUB channel for asynchronos
> stdout/stderr/displayhook/status changes.
> Thus a frontend has to be able to:
> * Do traditional request/replies.
> * Watch for incoming messages on the PUB/SUB channel.
> It has to do this at the same time and the only sane was of doing that
> is with an event loop.  Our current frontend.py does not use an event
> loop, and thus has to use subtle and buggy logic to fake it.
> Hope this helps more.  But it would help if you could explain what you
> mean by the "same API".

Ok. Here is my API (so far I have no sessions there):

In [1]: import jsonrpclib

In [2]: s = jsonrpclib.SimpleServerProxy("http://2.latest.sympy-gamma.appspot.com/test-service/")

In [3]: s.eval_cell("2+3")
Out[3]: '5'

In [4]: s.eval_cell("""\
   ...: from sympy import sin, integrate, var
   ...: var("x")
   ...: integrate(sin(x), x)
   ...: """)
Out[4]: '-cos(x)'

In [5]: s.eval_cell("""\
   ...: from sympy import sin, integrate, var
   ...: var("x")
   ...: a = integrate(sin(x), x)
   ...: """)
Out[5]: ''

In [6]: s.eval_cell("a.diff(x)")
Out[6]: 'sin(x)'

and this works from a terminal. The web browser that runs javascript
uses the *exact* same json-rpc messages as the terminal version.

So if I understand you correctly, you want a more rich API, but this
cannot be handled by the browser, right?

My main goal is to figure out a nice API, that the browser can use to
communicate with the server. For testing purposes, I'll also implement
this in a terminal too. My main goal is to have a notebook in the


More information about the IPython-dev mailing list