Skip to content

Instantly share code, notes, and snippets.

View foxgreek's full-sized avatar
🚵‍♂️
Focusing

Lukas Schlachter foxgreek

🚵‍♂️
Focusing
View GitHub Profile
@foxgreek
foxgreek / mercure.py
Created May 15, 2021 13:32 — forked from adamstep/mercure.py
Using Mercure with Django for Server-sent events
# Helper functions for publishing events, generating JWT tokens, and generating the Hub URL.
def publish_event(event_type, topic, targets):
"""
Publishes an event to the Mercure Hub.
event_type: The type of the event, can be any string
topic: The topic the event will be sent to. Only subscribers who request this topic will get notified.
targets: The targets that are eligible to get the event.
"""
token = get_jwt_token([], targets)