- 授权协议: Apache
- 开发语言: Python
- 操作系统: 跨平台
- 软件首页: https://github.com/KeepSafe/aiohttp
- 软件文档: https://aiohttp.readthedocs.org/en/stable/
软件介绍
aiohttp 是 asyncio 的 HTTP 客户端/服务端 (PEP 3156)。
特性
Web-server 有中间件和可插拔路由
服务器端简单使用示例:
import asyncio from aiohttp import web @asyncio.coroutine def handle(request): name = request.match_info.get('name', "Anonymous") text = "Hello, " + name return web.Response(body=text.encode('utf-8')) @asyncio.coroutine def wshandler(request): ws = web.WebSocketResponse() ws.start(request) while True: msg = yield from ws.receive() if msg.tp == web.MsgType.text: ws.send_str("Hello, {}".format(msg.data)) elif msg.tp == web.MsgType.binary: ws.send_bytes(msg.data) elif msg.tp == web.MsgType.close: break return ws @asyncio.coroutine def init(loop): app = web.Application(loop=loop) app.router.add_route('GET', '/echo', wshandler) app.router.add_route('GET', '/{name}', handle) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 8080) print("Server started at http://127.0.0.1:8080") return srv loop = asyncio.get_event_loop() loop.run_until_complete(init(loop)) loop.run_forever()
Python编程
[美]埃里克·马瑟斯 / 袁国忠 / 人民邮电出版社 / 2016-7-1 / CNY 89.00
本书是一本针对所有层次的Python 读者而作的Python 入门书。全书分两部分:第一部分介绍用Python 编程所必须了解的基本概念,包括matplotlib、NumPy 和Pygal 等强大的Python 库和工具介绍,以及列表、字典、if 语句、类、文件与异常、代码测试等内容;第二部分将理论付诸实践,讲解如何开发三个项目,包括简单的Python 2D 游戏开发如何利用数据生成交互式的信息图......一起来看看 《Python编程》 这本书的介绍吧!