Can you recommend a minimalistic python webserver that I can embedded in my Desktop Application.
7 Answers
How minimalistic and for what purpose?
SimpleHTTPServer comes free as part of the standard Python libraries.
If you need more features, look into CherryPy or (at the top end) Twisted.

- 8,198
- 6
- 64
- 63

- 6,341
- 2
- 28
- 42
-
1I strongly recommend CherryPy; I've been using it professionally for years and have been extremely happy with it. – Eli Courtwright Nov 19 '08 at 18:20
-
Strongly suggest Twisted (or Kamaelia) over the others. It knows how to integrate with UI mainloops used in desktop applications. – Ali Afshar Nov 20 '08 at 01:09
-
Wouldn't Twisted be over-kill for such a solution? – Phillip B Oldham Nov 20 '08 at 13:47
-
The original poster didn't really say anything about the purpose of the web server. If it's to provide a page that's read by a user at a time, and not too often, then Twisted is overkill. As way to provide a heavily-used data interface, it may not be. That's why I suggested a range of solutions. – Tim Lesher Nov 20 '08 at 15:15
-
1Strongly suggest CherryPy 3 over the others. It doesn't run anything in the main loop at all and is specifically designed to be embedded in this way. – fumanchu Nov 20 '08 at 20:59
I'm becoming a big fan of the newly released circuits library. It's a component/event framework that comes with a very nice set of packages for creating web servers & apps. Here's the simple web example from the site:
from circuits.lib.web import Server, Controller
class HelloWorld(Controller):
def index(self):
return "Hello World!"
server = Server(8000)
server += HelloWorld()
server.run()
Its WSGI support is no more complicated than that, either. Good stuff.

- 14,354
- 6
- 37
- 50
If you're doing a lot of concurrent stuff, you might consider Kamaelia's HTTPServer.

- 192,085
- 135
- 376
- 510
-
Kamaelia's great for concurrent stuff, but wouldn't it be quite a large library to include just for a minimal webserver? – Phillip B Oldham Nov 20 '08 at 13:52
-
There's a significant amount of stuff that could be trimmed out of it if someone was so inclined. The idea's been floated to make several "distributions" of Kamaelia, it just hasn't happened yet. (But yes, I agree that this may be a sizable library to include as is). – Jason Baker Nov 20 '08 at 20:23
If you want to use something from the standard library I would strongly recommend not using SimpleHTTPServer, but instead using wsgiref.simple_server
. SimpleHTTPServer is awkward and a rather nonsensical way to implement a web application, and while raw WSGI isn't terribly easy (but certainly possible), you have the option to use any WSGI-based framework on top of it. Also if you use wsgiref you will have the option to change to a server like CherryPy later (note that the server in CherryPy can be used separately from the rest of the framework, and you only need one file for just the server). For a "real" web application CherryPy has several advantages over wsgiref, but for a locally hosted application it's unlikely any of them will matter.
If you are making a desktop application you will need to launch a separate thread for either wsgiref or CherryPy. If that's fine, then a WSGI-based server would probably be easiest. If you don't want to launch a separate thread for the server then you most likely need to use Twisted.

- 889
- 7
- 7
I made this one. It just enhances Python's SimpleHTTPServer a bit to let you define custom actions depending on the request.

- 45,306
- 89
- 231
- 297