Skip to main content

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

[!NOTE] Documentation is WIP. See tests for more usage examples

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

assel-1.0.0.tar.gz (83.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

assel-1.0.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file assel-1.0.0.tar.gz.

File metadata

  • Download URL: assel-1.0.0.tar.gz
  • Upload date:
  • Size: 83.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for assel-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d405faafd327d8428b893684aab18bd72e14bdf8478ee442616cecbc90e7ad17
MD5 fb3b9af4b384b2b9a215fe18edbf438b
BLAKE2b-256 dd94dca15142eebc39ae75b2f2f9494b7c6a1adb2f9622867ac942c10c486a20

See more details on using hashes here.

File details

Details for the file assel-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: assel-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for assel-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d025a0a5134caf32fe1855d3e0e4e1d6a93ae2c81c3cb5ecd9bd17cbbab8bb41
MD5 8f9ccead119ebca46c85c56111a4c490
BLAKE2b-256 5124e3ff9b43f8cdb4f5556052c8693ec50b26e63522b7e7a24fcf5c92379d7b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page