基于asgi的web框架

nardis的Python项目详细描述


NARDIS

一个基于asgi的web框架。这是受到node.js的express框架的启发。

当前状态

仍然没有准备好生产。

此api目前处于试验阶段,随时可能更改。

因此,请不要将此用于生产应用程序。

不过,请你好好玩玩。随着api变得更加稳定,现阶段的任何反馈都是受欢迎的。

要求

Python3.6+

安装

通过PIP

运行以下命令:

$ pip install nardis

来源

要从源代码构建,请克隆此repo,然后:

$ python setup.py install

示例

这里有一个简单的例子。创建一个application.py,然后复制并粘贴这个:

fromnardis.asgiimportmainfromnardis.routingimportGetasget,Postaspostimportasynciotemplate_start="""<!doctype html><head><title>example</title></head><body>"""template_end="""</body>"""asyncdefindex(req,res):"""    This just demonstrates that you can write async code. Don't actually write this in production.    """awaitres.send(template_start,more=True)forxinrange(10,0,-1):awaitres.send(f"<p>{x}!</p>",more=True)awaitasyncio.sleep(1)awaitres.send("<p>liftoff!</p>",more=True)awaitres.send(template_end)asyncdefhello(req,res):"""    Try going to http://127.0.0.1:8000/hello/your_name/    You'll see "Hello, your_name!"    """name=req.params.get('name','world')awaitres.send(f"<h1>Hello, {name}!</h1>")routes=[get(r"^/?$",index),get(r"^/hello/(?P<name>\w+)/?$",hello),]config={'routes':routes,}app=main(config)# this is the ASGI applicationif__name__=='__main__':fromuvicorn.runimportrunrun(app,'127.0.0.1',8000)

然后:

$ python application.py

或者,您也可以执行以下操作:

$ uvicorn application:app

这将在http://127.0.0.1:8000上启动服务器

使用其他Web服务器

目前,乌维康是纳迪斯的属地。

代码库实际上并不使用uvicorn,但是这种依赖性允许您快速运行应用程序(参见上面的示例)。将来可能会删除此依赖项。

nardis还应该与其他基于asgi的web服务器一起工作,比如daphne。

要让daphne使用上面的示例代码,您可以执行以下操作:

$ daphne application:app

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用从PreparedStatement返回的RowId。getGeneratedKeys()?   selenium chrome驱动程序中下一个网站url的java空白页   java如何将参数化匿名类转换为lambda?   java JUnit在AfterClass上获取测试结果   java将动态XML/JSON内容与静态标记化负载进行比较,并检索标记值   java共享一个需要数据持久性的项目[数据库]   java在调用方法时获取意外的参数类型。getParameterTypes()   java如何用jdbc在swing中用另一个字段替换外键?   需要java Jersey Tomcat CDI依赖项解释   java如何生成UML图   java如何编写Jersey rest服务可以通过给定的spring代码访问   SpringMaven存储库管理器Nexus与Java依赖项的Artifactory   java将包从另一个项目导入eclipse中的当前项目   加密Java使用密码加密文件