API Docs

Invenio module for HTML5 server-sent events support.

class invenio_sse.ext.InvenioSSE(app=None)[source]

Invenio-SSE extension.

Extension initialization.

init_app(app)[source]

Flask application initialization.

init_config(app)[source]

Initialize configuration.

class invenio_sse.ext._SSEState(app)[source]

SSE state accessible via proxies.current_sse.

Initialize state.

messages(channel='sse')[source]

Message generator from the given channel.

publish(data, type_=None, id_=None, retry=None, channel='sse')[source]

Publish data as a server-sent event.

Parameters:
  • data – Event data, any object serialize to JSON.
  • type – Optional type of the event.
  • id – Optional event ID to set the EventSource object’s last event ID value.
  • retry – Optional reconnection time to use when attempting to send the event.
  • channel – Optional channel to direct events to different clients, by defaul sse.

Utilities

Utils.

invenio_sse.utils.format_sse_event(event)[source]

Encode a new event following SSE standard.

event: "New message"\n
id: 12345\n
data: {\n
data: "msg": "hello world",\n
data: }\n
retry: 10000\n\n
Parameters:event – A dictionary containing the keys data, id, retry and event. Only data field is mandatory, all the other fields are optional.
Returns:A formatted SSE message.

Configuration

Default configuration of the SSE module.

invenio_sse.config.SSE_REDIS_URL = 'redis://localhost:6379/0'

Redis URL used to push and read the messages.

It should be in the form redis://username:password@host:port/db_index.