aiohttp 和 websockets 之间的 difference/compatibility 是什么?

What's the difference/compatibility between aiohttp and websockets?

aiohttp 的 websocket 支持(即 WebSocketResponse)和 websockets(均提供异步支持)有何区别?可以混用吗?

它们是由不同的人维护的两个不同的库。两者都建立在 asyncio.

之上

websockets aims to be a simple easy to use library to implement websockets clients and servers and is maintained mostly by a single developer. On the other hand, aiohttp is a quite bigger library maintained by bigger team, offering not only websockets but, as the name suggests, HTTP functionality as well. Some of its functionality overlaps that of flask and requests,但采用异步方式。

在大小上,websockets约为4k LOC,而aiohttp约为40k LOC。如果您只需要一个简单易用的 websockets 客户端,请选择 websockets。如果您已经在使用 aiohttp 并且需要 websockets 功能,请使用 aiohttp 提供的功能。我看不出混合它们有什么意义。

注意一个细节可能会迫使需要在 Debian 8 中支持系统 Python 的人们做出选择:aiohttp 将其 minimum supported version 设置为 Python 3.5。 3(即Debian 9中的系统Python版本)。

虽然 aiohttp 人做出该决定有充分的理由,但 websockets 中较小的功能集允许该项目保持对 Python 3.4.x Debian 8 中的系统 Python,尽管对您自己的应用程序代码进行了一些调整以兼容 Python 3.4:https://websockets.readthedocs.io/en/stable/intro.html#python-lt-36