pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
518 B
17 lines
518 B
from collections.abc import AsyncIterable
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.sse import EventSourceResponse, ServerSentEvent
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/logs/stream", response_class=EventSourceResponse)
|
|
async def stream_logs() -> AsyncIterable[ServerSentEvent]:
|
|
logs = [
|
|
"2025-01-01 INFO Application started",
|
|
"2025-01-01 DEBUG Connected to database",
|
|
"2025-01-01 WARN High memory usage detected",
|
|
]
|
|
for log_line in logs:
|
|
yield ServerSentEvent(raw_data=log_line)
|
|
|