Embedded Web Server in Python? [closed]

≡放荡痞女 提交于 2020-01-22 09:42:52

问题


Can you recommend a minimalistic python webserver that I can embedded in my Desktop Application.


回答1:


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.




回答2:


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.




回答3:


If you're doing a lot of concurrent stuff, you might consider Kamaelia's HTTPServer.




回答4:


I've found web.py pretty easy to use : http://webpy.org/




回答5:


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.




回答6:


See the WSGI reference implementation.




回答7:


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



来源:https://stackoverflow.com/questions/302615/embedded-web-server-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!