又一个异步web服务器
pyxserver的Python项目详细描述
PYX是什么?
pyx是另一个用python编写的异步web服务器,使用asyncio 模块。
它又小又简单。除了python本身之外,它完全没有依赖关系。
然而PYX也经过精心设计,在压力和 危险环境。
如何安装?
只需使用PIP或类似工具:
pip install pyxserver
PYX能做什么?
pyx本身就是一个简单的静态文件服务器:
pyx -b localhost -p 8000 -r /some/where
这将启动pyx并将其绑定到localhost:8000,在 目录/some/where
您还可以使用pyx提供的小框架来编写 拥有动态Web应用程序:
importasynciofrompyximport(HttpHeader,HttpConnectionCB)@asyncio.coroutinedefreq_cb(req):resp=req.respond(200)resp.headers.append(HttpHeader('Content-Length',5))resp.headers.append(HttpHeader('Content-Type','text/plain'))yield fromresp.send()yield fromresp.send_body(b'hello')loop=asyncio.get_event_loop()conn_cb=HttpConnectionCB(req_cb)starter=asyncio.start_server(conn_cb,'127.0.0.1',8080,loop=loop)_server=loop.run_until_complete(starter)loop.run_forever()
请参见pyx.http.StaticRootResource的实现 更复杂的例子。
许可证
PYX是根据the MIT license条款授权的。