A Python implementation of resumable streams using Redis as the backend.
Heavily inspired by vercel/resumable-stream.
Add the following line to your requirements.txt
resumable-stream @ git+https://github.com/kortix-ai/resumable-stream-python@main
Add the following line to your pyproject.toml
resumable-stream = { git = "https://github.com/kortix-ai/resumable-stream-python" }
import asyncio
from redis.asyncio import Redis
from resumable_stream.runtime import create_resumable_stream_context
async def main():
redis = Redis(host='localhost', port=6379, db=0, decode_responses=True)
context = create_resumable_stream_context(redis, key_prefix="my-stream")
# Get resumable stream
stream = await context.resumable_stream("my-stream-id", lambda: my_stream_generator())
# Read from the stream
async for chunk in stream:
print(chunk)
if __name__ == "__main__":
asyncio.run(main())
- uv
- Redis server running locally (you can do
docker compose up -d
in this repo)
docker compose up -d # start redis server
uv sync # install dependencies
source .venv/bin/activate # activate virtual environment
python -m pytest # run tests