Assel
A sans I/O Server-Sent Events (SSE) library.
This library focuses on parsing and creating SSE event streams but does implement an a complete EventSource.
This means for example that the reconnection time, if present, is parsed and accessible to you, but the library does not help you with acting on it, ie. reconnecting.
Features:
- parse and serialize (receive and send) SSE events
- send comments
- stream API
- usable in sync and async contexts
Usage
There is a lower level "sans-io" API dealing with bytes and lists of Events and a higher level (a)sync stream API dealing with streams of bytes and Events
Parser API
# chunked up bytes stream as you (may) get it from IO
chunks = [b"da", b"ta: hel", b"lo\n\n", b"event: add\ndata: 5\n\ndata: hello\n\n"]
p = sse.Parser()
for chunk in chunks:
events = p.receive_bytes(chunk)
for event in events:
print(event)
should print:
Event(data='hello', event='message')
Event(data='5', event='add')
Event(data='hello', event='message')
stream API
import assel as sse
# chunked up bytes stream as you get it from IO
chunks = [b"da", b"ta: hel", b"lo\n\n", b"event: add\ndata: 5\n\n"]
for event in sse.parse(chunks):
print(event)
sending events
To send events, pass an Event to the send function. This will produce bytes suitable for giving to IO operations as part of an SSE stream.
You may attach comments to events or generate "stand-alone" comment lines.
# prints: b'event: add\ndata: 5\n\n'
print(sse.send(sse.Event("5", event="add")))
# prints: b':foo\ndata: hello\n\n'
print(sse.send(event=sse.Event("hello"), comment="foo"))
# prints: b':foo\n'
print(sse.send(comment="foo"))
Development
uv run pytest
Acknowledgements
This software was originally created as part of my work for the "Computing" Working Group of the Gesellschaft für wissenschaftliche Datenverarbeitung mbH Göttingen (GWDG) during my employment at the University of Göttingen.
Metadata
Release files for assel 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| assel-1.0.0.tar.gz | 83.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| assel-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 88.7 kB
Release files / assel-1.0.0.tar.gz
| Download URL | assel-1.0.0.tar.gz |
|---|---|
| Size | 83.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d405faafd327d8428b893684aab18bd72e14bdf8478ee442616cecbc90e7ad17
|
|
BLAKE2b-256 checksum How to use checksums |
dd94dca15142eebc39ae75b2f2f9494b7c6a1adb2f9622867ac942c10c486a20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / assel-1.0.0-py3-none-any.whl
| Download URL | assel-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d025a0a5134caf32fe1855d3e0e4e1d6a93ae2c81c3cb5ecd9bd17cbbab8bb41
|
|
BLAKE2b-256 checksum How to use checksums |
5124e3ff9b43f8cdb4f5556052c8693ec50b26e63522b7e7a24fcf5c92379d7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|