Skip to content

kortix-ai/resumable-stream-python

Repository files navigation

Resumable Stream Python

A Python implementation of resumable streams using Redis as the backend.

Heavily inspired by vercel/resumable-stream.

Installation

requirements.txt

Add the following line to your requirements.txt

resumable-stream @ git+https://github.com/kortix-ai/resumable-stream-python@main

Poetry

Add the following line to your pyproject.toml

resumable-stream = { git = "https://github.com/kortix-ai/resumable-stream-python" }

Usage

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())

Development

Requirements

  • uv
  • Redis server running locally (you can do docker compose up -d in this repo)

Setup

docker compose up -d # start redis server
uv sync # install dependencies
source .venv/bin/activate # activate virtual environment
python -m pytest # run tests

About

Like vercel/resumable-stream but python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages