views:

97

answers:

3

I want to write a simple python web application to provide a gui to a command line program (think of hg serve, for example). It would run locally only. I don't want it to have any external dependencies for an easier deployment, so python web programming in general wouldn't apply here

How can it be done with a minimal hassle? Any pointer how to do it easily with cgi or wsgi, string.Template or string.Formatter? I'd prefer a Python 2.6 solution, but even a Python 3.x one is OK. I'd also prefer using a few html templates to manually assembling html together.

UPDATE: The ideal solution would include ways

  • to process a form
  • to upload/download a file
  • to output html
  • to start a webserver
A: 

Are you looking for something like SimpleHTTPServer? http://docs.python.org/library/simplehttpserver.html#module-SimpleHTTPServer

Santiago Lezica
Well, it's part of what I'm looking for, please, see the update to my question.
Adam Schmideg
A: 

Maybe twisted is the way to go? Or do you consider this to be too much of an external dependency?

Jasper
There are dozens of wonderful python web frameworks, I know. This question is about NOT using any of them, including twisted.
Adam Schmideg
+4  A: 

The wsgiref package from the standard library has a simple server to serve wsgi applications. You can use it to run your own framework-less wsgi application, a minimal wsgi application isn't terribly difficult (see the hello world example at the end of the wsgiref documentation page)

You might want to relax the "standard library" requirement a little. You're going to have "dependencies" on your own modules anyway, is it really that bad to use something where someone else has already done the work? Some of the so-called "microframeworks" shouldn't be too much of a problem for deployment. Bottle for example, comes as a single file module and has no dependencies other than stdlib (haven't used Bottle yet myself, but I picked that one as an example mainly because of the single file/no dependencies)

Steven
+1 you made me reconsider my original requirement. Thanks for the microframework pointer. Bottle looks interesting.
Adam Schmideg
I can certainly recommend Bottle. I have been using it for exactly the scenario described in the question.
Muhammad Alkarouri