This example illustrates how to use built-in features for Server-sent events (SSE).
Note that, even though BlackSheep supports built-in features for SSE only since version 2.0.6, previous versions of the web framework also could support SSE, as they support response streaming.
Running the example:
- create a Python virtual environment
- install dependencies
- run with
uvicorn server:app
to test withuvicorn
, orhypercorn server:app
to test withhypercorn
- open the page in a web browser, you should see the message on the page updated every second, using information from the server
This example also shows how the is_stopping
function can be used to detect
when the application server is shutting down.
from blacksheep.server.application import is_stopping