一个非常轻量级和简单的api服务器,构建在socketserver模块上
meager的Python项目详细描述
微薄
meager是一个基于python中的socketserver模块构建的小型web框架。
安装
在PyPI上可以买到微薄的。
您可以使用pip安装meager:pip install meager
示例
这是使用meager的最简单方法,在请求返回到“/”时返回html。
该模块深受烧瓶的启发,使用方便,可读性强。
返回html
的示例importmeagerapp=meager.Server(host="0.0.0.0",port=8080)# Set binding ip address and port, default is localhost:2090@app.router.route("/")defindex(request):return"<h1>Hello world!</h1>"app.serve()
返回json
的示例importmeagerapp=meager.Server()example_dict={"key1":"val1","key2":"val2"}@app.router.route("/")defindex(request):returnexample_dict# It can detect if you're sending a dictionary# and automatically changes the "Content-Type:" header to application/json app.serve()