Pyjo.SSE - Server-Sent Events

from Pyjo.SSE import build_event, parse_event

Pyjo.SSE implements the Server-Sent Events protocol. Note that this module is EXPERIMENTAL and may change without warning!

An event is a dict with the keys type, text, id and, when it is built, comment.

Functions

Pyjo.SSE implements the following functions, which can be imported individually.

See also

Pyjoyment, https://mojolicious.org.

Ported from Mojo::SSE of Mojolicious 9.49.

class Pyjo.SSE.Event

A parsed Server-Sent Event.

Pyjo.SSE.build_event(event: Mapping[str, Any]) → bytes
data = build_event({'type': 'foo', 'text': 'bar', 'id': 23})

Build Server-Sent Event.

Pyjo.SSE.parse_event(buffer: bytearray) → Event | None
event = parse_event(bytearray(b'data: bar\r\n\r\n'))

Parse Server-Sent Event from a bytearray, which loses the parsed event. Returns None if no complete event was found.