API

class flask_sse.Message(data, type=None, id=None, retry=None)

Data that is published as a server-sent event.

__init__(data, type=None, id=None, retry=None)

Create a server-side event.

Parameters:
  • data – The event data. If it is not a string, it will be serialized to JSON using the Flask application’s JSONEncoder.
  • type – An optional event type.
  • id – An optional event ID.
  • retry – An optional integer, to specify the reconnect time for disconnected clients of this stream.
to_dict()

Serialize this object to a minimal dictionary, for storing in Redis.

class flask_sse.ServerSentEventsBlueprint(name, import_name, static_folder=None, static_url_path=None, template_folder=None, url_prefix=None, subdomain=None, url_defaults=None)

A flask.Blueprint subclass that knows how to publish, subscribe to, and stream server-side events.

messages(channel=u'sse')

A generator of Message objects from the given channel.

publish(data, channel=u'sse', type=None, id=None, retry=None)

Publish data as a server-side event.

Parameters:
  • data – The event data. If it is not a string, it will be serialized to JSON using the Flask application’s JSONEncoder.
  • channel – If you want to direct different events to different clients, you may specify a channel for this event to go to. Only clients listening to the same channel will receive this event. Defaults to “sse”.
  • type – An optional event type.
  • id – An optional event ID.
  • retry – An optional integer, to specify the reconnect time for disconnected clients of this stream.
redis

A redis.StrictRedis instance, configured to connect to the current application’s Redis server.

stream()

A view function that streams server-side events. Ignores any Last-Event-ID headers in the HTTP request.