Skip to main content

Asynchronous recoverable SSE (Server-Sent Events) push toolkit, supporting Redis and in-memory backend.

Project description

resumable-sse

Asynchronous recoverable SSE (Server-Sent Events) push toolkit, supporting Redis and in-memory backend.

✨ Features

  • ✅ Seamless integration with async generators (async for)
  • 🔁 Resumable message stream support with Last-Event-ID
  • 💾 Backend-agnostic: in-memory or Redis support
  • ⚙️ Clean abstraction, minimal API surface
  • 🧪 Easy to test, extendable for custom storage backends

📦 Installation

pip install resumable-sse

Or from source:

git clone https://github.com/vvanglro/resumable-sse.git
cd resumable-sse
pip install -e .

🚀 Quick Start

Using with FastAPI:

import asyncio
from fastapi import FastAPI, Request
from sse_starlette.sse import EventSourceResponse
from resumable_sse.factory import get_streamer

app = FastAPI()
streamer = get_streamer(backend="memory")

async def fake_generator():
    for word in ["Hello,", "I'm an AI.", "Nice to meet you."]:
        yield word
        await asyncio.sleep(1)

@app.get("/stream")
async def stream(request: Request, session_id: str):
    return EventSourceResponse(
        streamer.stream(session_id=session_id, generator=fake_generator())
    )

Supports resume with:

GET /stream?session_id=abc

🔌 Redis Backend Example

import redis.asyncio as redis
from resumable_sse.factory import get_streamer

redis_client = redis.Redis()
streamer = get_streamer(backend="redis", redis_client=redis_client)

📘 API Reference

async def stream(
    self,
    session_id: str,
    generator: ContentStream,
    last_id: str = "0",
) -> AsyncGenerator[dict, None]:
  • session_id: Unique ID per conversation or stream session
  • last_id: Resume position (used with Last-Event-ID)
  • generator: Async generator function that yields message chunks

🧪 Run Tests

pytest tests/

📁 Project Structure

resumable_sse/
├── base.py           # Abstract base class
├── memory.py         # In-memory implementation
├── redis.py          # Redis implementation
├── factory.py        # Factory for backend selection
├── __init__.py
README.md
pyproject.toml

📄 License

MIT License


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

resumable_sse-0.1.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

resumable_sse-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file resumable_sse-0.1.0.tar.gz.

File metadata

  • Download URL: resumable_sse-0.1.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.20

File hashes

Hashes for resumable_sse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 95f089d6df06309d97a5da36bba10ccf2520699e1848bdca1d599d87f6557c16
MD5 a3d8273b6328d94e404bc879c7658d9f
BLAKE2b-256 7adc66330266bd98ebb91a095dec8a9024fe0cff26b3ebfebd5abfae2a72ca7c

See more details on using hashes here.

File details

Details for the file resumable_sse-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for resumable_sse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a46ad3b981ffb8006b729fc0fcf605de20143ffeff140cbd48ec1794b69c4f07
MD5 a9176cb9b99fcc8dedd3ecf855b7341b
BLAKE2b-256 2739c8d3eae6836a0e9586741fc3e243e0f69d7d6b6134dbc8b880a9cd0dbfeb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page