Implementation:TobikoData Sqlmesh API Events
| Knowledge Sources | |
|---|---|
| Domains | Web_Server, REST_API |
| Last Updated | 2026-02-07 20:00 GMT |
Overview
Concrete tool for streaming real-time SQLMesh console events via Server-Sent Events (SSE) provided by the SQLMesh web server.
Description
This module exposes a FastAPI endpoint that implements Server-Sent Events for real-time event streaming. The endpoint maintains a queue of console listeners registered in the application state. Events are pushed to all connected clients with a 15-second ping interval to keep connections alive. The async generator pattern ensures efficient handling of multiple concurrent client connections.
Usage
This endpoint is called by the SQLMesh web UI to establish a persistent connection for receiving real-time updates. The client uses an EventSource connection to receive plan progress updates, test results, apply status changes, and other console events. The ping mechanism prevents connection timeouts during long-running operations.
Code Reference
Source Location
- Repository: TobikoData_Sqlmesh
- File: web/server/api/endpoints/events.py
Signature
@router.get("")
async def events(request: Request) -> EventSourceResponse
Import
from web.server.api.endpoints.events import router
I/O Contract
Inputs
| Endpoint | Method | Parameters | Description |
|---|---|---|---|
| /api/events | GET | None | Opens SSE connection for streaming events |
Outputs
| Endpoint | Response Type | Description |
|---|---|---|
| /api/events | EventSourceResponse | Stream of ServerSentEvent messages with 15s pings |
Usage Examples
# JavaScript client example
const eventSource = new EventSource("http://localhost:8000/api/events");
eventSource.addEventListener("plan_progress", (event) => {
const data = JSON.parse(event.data);
console.log("Plan progress:", data);
});
eventSource.addEventListener("ping", (event) => {
const data = JSON.parse(event.data);
console.log("Keep-alive ping:", data.timestamp);
});
eventSource.onerror = (error) => {
console.error("SSE connection error:", error);
eventSource.close();
};