[IPython-dev] make ipython work over web

Brian Granger ellisonbg@gmail....
Sat Mar 27 13:42:52 CDT 2010


Ondrej,

> 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)'

OK, if this is the only API you want, it is possible.  BUT, a few points:

* It is completely blocking and synchronous.  We can create such an
API using 0MQ, but it obviously has limitations.
* It handles stdout in a completely synchronous manner.  I think we
can do this too (again limitations apply).

You are going to have to work *very* hard using json-rpc alone to get
asynchronous stdout/stderr/displayhook.  Here is the design that you
want that will entirely do what you want:

client<--jsonrpc-->bridge<--0MQ-->kernel

The bridge would be a fully asynchronous 0MQ client and would receive
the asynchronous 0MQ stdout/stderr/displayhook and simply put them in
queues.  The bridge would also be a json-rpc server.  with methods
like:

eval_cell  # submit but don't block. get back an object that would
allow you to see if the cell was done evaluating.
complete # again submit but don't return.  Similar logic.
get_stdout  # get all the stdout that has been written thus far
get_stderr  # get all stderr that has been written thus far.

You basically want to put a blocking API on top of the asynchronous 0MQ API.

This type of thing should be be too difficult to write using 0MQ and
we can help out.  If you are serious about this, let me know and
Fernando and I can come up with a plan.
We could probably develop this in the pyzmq tree for now.

Cheers,

Brian

>
>
> 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
> browser.
>
> Ondrej
>



-- 
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu
ellisonbg@gmail.com


More information about the IPython-dev mailing list