What's the difference between aiohttp
's websocket support (i.e. WebSocketResponse
) and websockets (both offer an async support)? Can they be mixed?
aiohttp is used to build useful libraries built on top of it, and there's a page dedicated to list them: Third-Party libraries. There are also projects that leverage the power of aiohttp to provide end-user tools, like command lines or software with full user interfaces.
The aiohttp (http://aiohttp.readthedocs.io/) framework is a popular asynchronous framework based on the asyncio library, which has been around since the first days of the library. Like Flask, it provides a request object and a router to redirect queries to functions that handle them.
It provides a bidirectional channel for delivering data between clients and servers. It gives you the flexibility of a TCP connection with the additional security model and meta data built into the HTTP protocol. For more details on the WebSocket protocol refer to RFC 6455, which is the version supported on Heroku.
They are two different libraries maintained by different people. Both are built on top of 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
, but in a async fashion.
In terms of size, websockets
is about 4k LOC, while aiohttp
is about 40k LOC. If you just need a simple and easy to use websockets client, go for websockets
. If you are already using aiohttp
and need websockets functionality, use what aiohttp
has to offer. I don't see a point in mixing them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With