File size: 495 Bytes
a34cccb
 
 
 
 
 
 
 
9582187
a34cccb
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import httpx
from typing import AsyncGenerator

class SSEClient:
    def __init__(self, url: str):
        self.url = url

    async def connect(self) -> AsyncGenerator[str, None]:
        print("a")
        async with httpx.AsyncClient(timeout=None) as client:
            async with client.stream("GET", self.url) as response:
                async for line in response.aiter_lines():
                    if line.startswith("data:"):
                        yield line[5:].strip()