Skip to content

Instantly share code, notes, and snippets.

View lbatteau's full-sized avatar

Lukas Batteau lbatteau

  • Deepdesk
  • 21:15 (UTC +01:00)
View GitHub Profile
@app.get("/sse/publish")
async def get(channel: str = "default", redis: Redis = Depends(depends_redis)):
await redis.publish(channel=channel, message="Hello world!")
return ""
@lbatteau
lbatteau / stream.py
Last active January 18, 2021 20:25
stream
@app.get("/sse/stream")
async def stream():
return EventSourceResponse(subscribe)
@lbatteau
lbatteau / subscribe.py
Last active January 18, 2021 20:23
subscribe.py
async def subscribe(channel: str, redis: Redis) -> AsyncGenerator:
(subscription,) = await redis.subscribe(channel=Channel(channel, False))
while await subscription.wait_message():
yield {"event": "message", "data": await subscription.get()}
@lbatteau
lbatteau / sse-fastapi-redis.py
Last active October 13, 2024 22:30
Server-Sent Events in FastAPI with async Redis Pub/Sub
from aioredis import Channel, Redis
from fastapi import FastAPI
from fastapi.params import Depends
from fastapi_plugins import depends_redis, redis_plugin
from sse_starlette.sse import EventSourceResponse
from starlette.responses import HTMLResponse
html = """
<!DOCTYPE html>
<html>
@lbatteau
lbatteau / README.markdown
Created October 30, 2012 12:38 — forked from gudbergur/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things

This is a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
    source: (typeahead, query) ->
 # this function receives the typeahead object and the query string