Earlier this year I did some development involving Server-sent events (SSE) using Flask. I found there is no official documentation on how to best handle this. Since the specification is simple I ended up implementing it myself. However, I think there is room for improvement.
I find there are a couple of problems with working with SSE and Flask:
The same points hold true for WebSockets as they are similar.
@mitsuhiko did a talk at PyBay 2016 about Flask, and one of the last sections was on WebSockets with Flask. I'm linking to the part about WebSockets here for future reference:
Flask is not going to define "best practices" for most things, as that's up to the developer. There is Flask-SSE for SSE, Flask-Sockets or Flask-SocketIO for websockets.
The takeaway from the talk you linked is that Flask itself doesn't do anything, it's a separate service, which the extensions above cover. If you're interested in adding async support to Flask itself, I'm investigating ASGI.
I'd argue that it would be useful to have a section for this under _Patterns for Flask_ is useful and relevant. There already are patterns for specific technologies such as _Celery Based Background Tasks_. I know about the Flask extensions, but they all introduce problems:
flask runThe thing about the linked talk I find useful is that @mitsuhiko advocates for not using Flask for the actual websocket server. Stating that _"Flask doesn't do websockets and SSE very well yet, and therefore you should implement it as a separate service. You should do this using signed tokens."_ is useful to everyone looking at the documentation.
Since both SSE and websockets are becoming increasingly popular, I really think they should be addressed in some way in the documentation. It doesn't even have to be best practices, just give the user a good starting point.
I vote for adding documentation about SSE topic. Because some points of implementation of SSE on flask are not clear at all. For example I'm getting resource leaking and don't know how to avoid it https://stackoverflow.com/questions/47868205/detect-client-disconnect-in-flask-for-streaming-response-server-sent-events-s.
Or if flask team agrees that flask is not good for SSE and other async services it would be great to explicit note it in documentation as well.
Most helpful comment
I'd argue that it would be useful to have a section for this under _Patterns for Flask_ is useful and relevant. There already are patterns for specific technologies such as _Celery Based Background Tasks_. I know about the Flask extensions, but they all introduce problems:
flask runThe thing about the linked talk I find useful is that @mitsuhiko advocates for not using Flask for the actual websocket server. Stating that _"Flask doesn't do websockets and SSE very well yet, and therefore you should implement it as a separate service. You should do this using signed tokens."_ is useful to everyone looking at the documentation.
Since both SSE and websockets are becoming increasingly popular, I really think they should be addressed in some way in the documentation. It doesn't even have to be best practices, just give the user a good starting point.