👀 Live preview (open this page → events stream in below)

// Connecting to ws://<host>/ws/leaderboard …

Open a benchmark in another tab — you'll see leaderboard events arrive here in real time.

1. Benchmark progress

ws /ws/benchmark
// Track a running benchmark by job_id.
// Basic syntax — works in browser console, Node, or any JS runtime.

const ws = new WebSocket(`${location.origin.replace('http','ws')}/ws/benchmark`);
ws.onopen = () => {
  ws.send(JSON.stringify({ type: 'subscribe', job_id: 42 }));
};
ws.onmessage = (e) => {
  const msg = JSON.parse(e.data);
  if (msg.type === 'progress') {
    console.log(`Job ${msg.job_id}: ${msg.progress}% (${msg.status})`);
  }
};
Browser JS

2. Leaderboard live updates

ws /ws/leaderboard
// Get notified every time a benchmark finishes and the leaderboard moves.
// Use this to build Kaggle-style "jumped 3 spots!" alerts.

const ws = new WebSocket(`${location.origin.replace('http','ws')}/ws/leaderboard`);
ws.onopen = () => ws.send(JSON.stringify({ type: 'subscribe', dataset_id: 1 }));
ws.onmessage = (e) => {
  const msg = JSON.parse(e.data);
  if (msg.type === 'leaderboard_update') {
    console.log(`#${msg.rank} ${msg.model_name} — score ${msg.score}`);
    console.log(`  prev rank: ${msg.previous_rank} → new rank: ${msg.rank}`);
  }
};
Browser JS

3. In-app notifications

ws /ws/notifications
// Receive in-app notifications in real time: benchmark completed,
// leaderboard rank changed, competition started, comment reply.

const ws = new WebSocket(`${location.origin.replace('http','ws')}/ws/notifications`);
ws.onmessage = (e) => {
  const n = JSON.parse(e.data);
  if (n.type === 'notification') {
    showToast(n.title, n.body);
    // e.g. "Leaderboard moved" — "Your model X jumped from #5 to #2!"
  }
};
ws.onclose = () => console.log('Reconnect with exponential backoff…');
Browser JS

4. Python (websockets lib)

client lib
# pip install websockets
import asyncio, json, websockets

async def main():
    async with websockets.connect("ws://localhost:8000/ws/leaderboard") as ws:
        await ws.send(json.dumps({"type": "subscribe", "dataset_id": 1}))
        async for raw in ws:
            msg = json.loads(raw)
            if msg.get("type") == "leaderboard_update":
                print(f"#{msg['rank']}  {msg['model_name']}  "
                      f"score={msg['score']:.4f}")

asyncio.run(main())
Python ≥3.7

5. CLI one-liner

openbenchml-cli
# Stream leaderboard events from the terminal:
npx openbenchml watch --channel leaderboard --dataset-id 1

# Or benchmark progress:
npx openbenchml watch --channel benchmark --job-id 42

# Or notifications:
npx openbenchml watch --channel notifications
Shell (npm 4.0.0+)

6. Quick health check

http /health
# See how many WS clients are connected right now:
curl -s http://localhost:8000/health | jq .websocket_connections

# Sample response:
# {
#   "status": "healthy",
#   "version": "4.0.0",
#   "websocket_connections": 12,
#   "database_status": "connected",
#   ...
# }
Shell + jq