---
title: "💭 sysid/sse-starlette"
description: "!https://github.com/sysid/sse-starlette"
date: 2023-10-12
published: true
tags:
  - htmx
  - webdev
  - thought
template: link
---


<div class="embed-card embed-card-external">
  <a href="https://github.com/sysid/sse-starlette" class="embed-card-link" target="_blank" rel="noopener noreferrer">
    <div class="embed-card-image">
      <img src="https://opengraph.githubassets.com/76f56f9c8153bbb3109bbc24a9db21c0bb5e3e31731ad93f467312d26edfcef3/sysid/sse-starlette" alt="GitHub - sysid/sse-starlette — Contribute to sysid/sse-starlette development by creating an account on GitHub." loading="lazy">
    </div>
    <div class="embed-card-content">
      <div class="embed-card-title">GitHub - sysid/sse-starlette</div>
      <div class="embed-card-description">Contribute to sysid/sse-starlette development by creating an account on GitHub.</div>
      <div class="embed-card-meta">GitHub &middot; github.com</div>
    </div>
  </a>
</div>


sse-starlette provides server sent events for startlette and FastApi.  I'm evaluating for use with htmx.

## Installation:

``` bash
pip install sse-starlette
```
## Usage:

``` python
import asyncio
import uvicorn
from starlette.applications import Starlette
from starlette.routing import Route
from sse_starlette.sse import EventSourceResponse

async def numbers(minimum, maximum):
    for i in range(minimum, maximum + 1):
        await asyncio.sleep(0.9)
        yield dict(data=i)

async def sse(request):
    generator = numbers(1, 5)
    return EventSourceResponse(generator)

routes = [
    Route("/", endpoint=sse)
]

app = Starlette(debug=True, routes=routes)

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000, log_level='info')
```

!!! note

    This post is a <a href="/thoughts/" class="wikilink" data-title="Thoughts" data-description="These are generally my thoughts on a web page or some sort of url, except a rare few don&#39;t have a link. These are dual published off of my..." data-date="2024-04-01">thought</a>. It's a short note that I make
    about someone else's content online <a href="/tags/thoughts/" class="hashtag-tag" data-tag="thoughts" data-count=2 data-reading-time=3 data-reading-time-text="3 minutes">#thoughts</a>
