tags:

views:

122

answers:

3

Given that I know no web frameworks in Python and would like to keep it Very Simple at the moment (as I am Very Stupid), for what is a prototype of sketchy longevity, are there any streamlined, simple, "batteries-included" modules for this? (It is also too early in my Python career to evaluate frameworks, select one, and learn it.) I see a module named "Cookie," which could serve as a foundation, but nothing session-specific.

I'm familiar with the basic session concepts, having used them in classic ASP and gotten into the nuts-and-bolts of them in Perl, but I am not seeing a lot for Python. Beaker looks interesting, but then the documentation seems to require middleware with WSGI and I'm back to the frameworks problem.

I've found an old recipe on ActiveState for sessions, which could obviously use some buffing up. The information being held is not anything anyone would mind having been grabbed, so while I am normally quite security conscious, I would be willing to be a little bit more lax with this prototype.

Or is this a "roll-your-own" problem?

I will be using Python 2.6 on IIS 7.0.

+3  A: 

I think the web2py (web framework) is easy enough for you. I think it is the simplest approach of making a website or webservice. It will be also easier, than to understand Cookie or the other modules of python related to web-things.

You can start a session, by just typing:

session.your_session_name = "blabla" # or whatever you want to store

To make a cookie, just look here.

In web2py you don't have to configure anything. Just download it and start web2py.py. (you must have python 2.6 < installed.) You can also find some examples and a web-slide.

The Python Cookie module does nothing more than to hold some values in a dictonary-like object, but I think you have to store it yourself on your harddisk.

Joschua
It's a framework, not a module, which is sad. It seems to be built on top of CherryPy. And it's got an Admin Interface, so that's something else to fuss over, even sadder. And the stuff on the home page mentions integration with Twitter -- that's when I reach for my revolver.
MetaHyperBolic
yes it's a bit fussy, but what do you want to made with just a cookie module? And btw. response.cookies['name'] of web2py is built on pythons SimpleCookie of the Cookie module.
Joschua
It is not built on top of cherrypy. It only uses the cherrypy web server if you do not have a better web server. If you have Apache+mod_wsgi for example it does not uses any cherrypy code.
mdipierro
Minor correction to the original post. Sessions are always on unless disabled. In the following code: session.your_session_name = "blabla""your_session_name" is not your session name. It would be a variable you are storing the session with name "your_session_name". For example: session.your_variable = "bla" session.your_other_variable = "blablabla"
mdipierro
@MetaHyperbolic. The admin interface is an app built on web2py that ships with web2py, that can be removed, and it is not needed fr web2py to work. That admin interface uses twitter for notification of news. The underlying libraries are just python modules (like the DAL or the template engine or the form generation) which you can access from the shell. It is true that the web2py modules have a lot of interdependence so if you only need sessions you should consider lighter.
mdipierro
A: 

CherryPy is worth looking into. Yes it is a framework, and yes it requires WSGI, but it is extremely lightweight compared to other more robust alternatives.

There is another question that was answered on SO that gives a brief example on how to manage sessions with CherryPy. As you can see it makes it very easy to get up and running quickly.

Lastly, here is a little document about setting up IIS for use with CherryPy.

jathanism
A: 

WSGI is not a framework, nor does it require that you choose one -- it's THE standard way to run any Python web app framework on any Python-supporting web server, including a CGI one. If you have a WSGI application named app, and want to run it on CGI, see the docs and use wsgiref.handlers.CGIHandler().run(app), as the docs say.

So, you can perfectly well use Beaker via WSGI (on top of CGI) -- e.g., take the example in Beaker's docs and just add (the needed imports and) the run call above (using the wsgi_app object that example constructs, plus of course a session.save and as well needed as, again, the Beaker docs explain right afterwards).

Rich or heavy frameworks have their place but so do lightweight, flexible components like Beaker -- and WSGI middleware is a great way to leverage such components without requiring any "framework-y" arrangements, just good old WSGI (on top of CGI or anything else).

BTW, the best way to run WSGI on IIS might be isapi-wsgi (I can only say "might" because I have no IIS installation on which to test it;-). But as long as you code to WSGI (with any framework or with none at all), that will only be an optimization -- your application won't change (net of what handler's run or equivalent method you need to call;-) whether it's running on CGI, IIS via ISAPI, Google App Engine, or any other server-and-interface-thereto combination

Alex Martelli
It's still not relevant. I'm looking for Python modules. Not frameworks, not other things I have to layer in. These constraints were solvable in Perl, simply by using the CGI::Session module, which is unlovely but functional.If the answer is "I do not know of Python modules which do this; you must roll your own" that's perfectly okay to say.
MetaHyperBolic
@Meta, wsgiref is a module, beaker.middleware is a module, isapi-wsgi -- they're not frameworks, and what you call "layering in" (by which I assume you mean decorators and other higher-order functions) is simply one of the ways to use a module in Python, no more and no less than calling functions from it or inheriting from its classes -- Python's apt to use functional idioms (such as HOFs, genexps and other iterators, etc) no less than procedural or OOP ones (Session is not "functional" in the paradigm sense, of course;-). Tragic that you just refuse to see this, really.
Alex Martelli
It's tragic that you fail to understand what I am asking. You're suggesting I install something else (isapi-wsgi). I'm just looking for a module. Something which does not require installing frameworks, or .exes, or stuff that sits in the ISAPI layer. You're trying to sell me on an SUV when I'm looking for a moped. If you don't have mopeds, that's completely okay, I will not be upset. Perl could do this with CGI::Session. No ISAPI layer stuff, no frameworks. It was just a module. If Python does not have an analogous module, that's an acceptable outcome. That appears to be the case.
MetaHyperBolic
@Meta, read my response carefully again: isapi-wsgi is a "by the way" (you **know** what BTW stands for, do you?) in the fourth paragraph (first sentence only: the rest of the paragraph explains that it doesn't really matter except as an optimization!). The first three paragraphs explain how you run a wsgi app (which is just a function you write to respect certain conventions) on top of CGI with the Python standard library -- no installing frameworks, no exes, no stuff that sits in the ISAPI layer. Your rant and your inability to read plain English are truly tragic!
Alex Martelli