Metadata-Version: 2.4
Name: larzsse
Version: 0.1.0
Summary: Server-Sent Events (SSE): a thread-safe broadcaster and a client, over plain HTTP. Pure Python, no async, zero dependencies.
Author: larz-scripter
License: MIT
Project-URL: Homepage, https://github.com/larz-scripter/larzsse
Project-URL: Repository, https://github.com/larz-scripter/larzsse
Project-URL: Issues, https://github.com/larz-scripter/larzsse/issues
Keywords: sse,server-sent-events,streaming,realtime,eventsource,push,http,broadcaster,zero-dependency
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# larzsse

**Server-Sent Events — server and client. Pure Python, no async, zero deps.**

SSE is the simplest way to push a live stream of events from server to browser
(or any client) over plain HTTP — one long-lived `text/event-stream` response.
larzsse gives you both ends: a thread-safe **Broadcaster** that fans events out to
every connected client, and a **client** that connects and iterates parsed events.

```python
from larzsse import Broadcaster, connect

bus = Broadcaster()
server = bus.serve("127.0.0.1", 8080)          # streams at /events
bus.publish("hello", event="greeting")         # every client receives it

for ev in connect("http://127.0.0.1:8080/events"):
    print(ev.event, ev.data)
```

## Why

- **Both ends included.** A `Broadcaster` (subscribe/publish/unsubscribe, with
  keepalives and a built-in threaded server) and a `connect()` client that parses
  the stream into `Event(event, data, id)` objects.
- **No async, no dependency.** Plain sockets and threads — a lightweight
  complement to WebSockets ([larzws](https://github.com/larz-scripter/larzws))
  when you only need server → client push (live dashboards, progress, notifications,
  log tailing).
- **Correct wire format.** `format_event`/`parse_events` handle `data:`/`event:`/
  `id:`/`retry:`, multiline data, and comment keepalives — round-trip clean.

## Install

```bash
pip install larzsse
```

## Usage

```python
from larzsse import Broadcaster, connect, format_event

bus = Broadcaster()
bus.serve("0.0.0.0", 8080, path="/events")
bus.publish("payload", event="update", id="42")
bus.client_count

# embed in your own server: stream a subscribed client's events()
client = bus.subscribe()
for chunk in client.events():     # SSE strings; write to the response
    ...

# client
for ev in connect("http://host/events"):
    ev.event, ev.data, ev.id
```

## Tests

```bash
python -m unittest discover -s tests -v   # 13 tests incl. live SSE over HTTP
```

## The Larz stack

One of 30+ pure-Python, zero-dependency libraries at
[github.com/larz-scripter](https://github.com/larz-scripter).

## License

MIT © larz-scripter
