Persistent python object and the Web

R

ramon.aragues

Hi,

I'd like to know if I am trying to do something impossible or I am just
being unable to find how to do it. In the latter case, please... help
me...

I´ve implemented a python class Graph, which handles graphs (with its
nodes, edges, finding paths, etc). In my text-menu interface, I can add
nodes, delete nodes, add edges, find shortest routes, etc. I simply
create a graph_object before presenting the text menu and then, when a
user choses a command (eg. add-node) I call the method of this object
with the appropiate parameters.

Now... I need to "translate" this text-menu interface to a web
interface. The same as the text-menu interface, but letting the user do
it through the web. I have created an HTML that lets the user enter the
parameters and chose which command to execute by pushing different
buttons. But...

My problem is that I don't know how to create a graph_object that
remains persistent through time (it has to be the same graph_object for
the first command as for the last one "pushed" by the user). I want to
be able to create the object when the user enters the web page (by
calling graph_object = Graph(id="graph1")) and then make calls to
graph_object methods when the user pushes a button.

I'm using python2.3, mod_python and Apache.

Any help will be greatly appreaciated.

Ramon
 
J

Jeff Shell

The ZODB (Zope's object database, which can be downloaded and installed
separately from Zope) and Durus (part of the Quixote family, I believe)
are both high quality persistent Python object stores that are used
heavily for web sites.

I've never used the ZODB outside of Zope, and haven't used Durus yet.
But there may be some examples written up about how to use them with
mod_python.

You *might* even be served by the built-in 'shelve' module.
http://docs.python.org/lib/module-shelve.html
 
E

Esben Pedersen

My problem is that I don't know how to create a graph_object that
remains persistent through time (it has to be the same graph_object for

One possibility is to have a remote procedure call server that stores
the graph running seperately from your wab application.

Your web application then simply calls the rpc which is running in a
seperate process which gives you the persistence.

A good choice is the xmlrpc module in the standard python distribution,
which makes it simple to comunicate between processes.

/Esben
 
B

bruno modulix

Hi,

I'd like to know if I am trying to do something impossible or I am just
being unable to find how to do it. In the latter case, please... help
me...
(snip)
>
My problem is that I don't know how to create a graph_object that
remains persistent through time (it has to be the same graph_object for
the first command as for the last one "pushed" by the user). I want to
be able to create the object when the user enters the web page (by
calling graph_object = Graph(id="graph1")) and then make calls to
graph_object methods when the user pushes a button.

I'm using python2.3, mod_python and Apache.
You may want to have a look at ZODB - the Zope object database. It has
been developped for Zope, but can be used without.
 
B

Bengt Richter

Hi,

I'd like to know if I am trying to do something impossible or I am just
being unable to find how to do it. In the latter case, please... help
me...

I=B4ve implemented a python class Graph, which handles graphs (with its
nodes, edges, finding paths, etc). In my text-menu interface, I can add
nodes, delete nodes, add edges, find shortest routes, etc. I simply
create a graph_object before presenting the text menu and then, when a
user choses a command (eg. add-node) I call the method of this object
with the appropiate parameters.
How much total data is involved in the state of the Graph object?
If it's typed in, it can't be that much? Or do you automatically generate
huge subtrees etc.? Anyway, the amount will influence your options.

Then the question is where you want the state to persist. A small amount
can be carried right in the url. Or in preset values in forms, which can
have hidden elements, or in javascript variables that are set from script
parts that represent the state, or cookies that can contain references to
data stored one way or another on the server.
Now... I need to "translate" this text-menu interface to a web
interface. The same as the text-menu interface, but letting the user do
it through the web. I have created an HTML that lets the user enter the
parameters and chose which command to execute by pushing different
buttons. But...
You could conceivably implement the whole thing via javascript in an html
page that runs entirely in the client browser, but that probably wouldn't
be as much fun as python ;-)
My problem is that I don't know how to create a graph_object that
remains persistent through time (it has to be the same graph_object for
the first command as for the last one "pushed" by the user). I want to
be able to create the object when the user enters the web page (by
calling graph_object =3D Graph(id=3D"graph1")) and then make calls to
graph_object methods when the user pushes a button.

I'm using python2.3, mod_python and Apache.

Any help will be greatly appreaciated.
If the state is not too huge, I think I might first create
Graph dump and load methods that would output a nice text
representation of the graph state, and then use a textarea
form element to carry that info, which would get submitted
along with the visible form data. (You could make it all visible
for debugging). You could roll your own format suitable for
textarea transfer. Or you might consider using pickle.Pickler
to create string representations of state info (even a whole tree
if you want to save everything) and maybe do something simple
to make the resulting string ok for a textarea (I don't know
if it can be used as is with protocol 0).
Then you could use pickle.Unpickler to reconstitute what you pickled
when it comes back to the server from the submittal of the textarea
(whose default content you set up each time you serve a web page)
when it comes back again.

Then on the server you can just create an empty Graph instance
an use the submitted textarea state for the load method, and then
go on with the indiviual command data, which would update the Graph
instance state and then you return a web page with the textarea
preset to whatever you get from your graph instance .dump method.

This would be just cgi with no server data base and no cookies or
any of that stuff. Everything persists in the page form data that
is handed back and forth. The client should be able to save the page
to disk and bring it up again, and if your actions and hrefs are
absolute, they should go back to your server.

Anyway, you should be able to test this theory with a simple page
with a simple form. I may have forgotten some gotcha ;-)

If you have really big data, you might want to have it persist
on the server one way or another.

Regards,
Bengt Richter
 
R

ramon.aragues

Thanks to all for your help.

My graphs are huge (and contain much more information than the list of
nodes and their edges... I am working with protein-protein interaction
networks) so I have decided to have a persistent object on the server.
I first had to make my objects "pickable" (which was not obvious, since
they also contain database connections) but I think now I am on the
right way. The only problem I see is that the web interface will be
slower, since it has to "load graph-process it -dump graph" after each
command, but I guess that is the price I'll have to pay.

Thanks a lot again!

Ramon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top