f1verse
f1verse · Python

How do I read the Formula 1 live timing feed in Python?

Use f1verse.sources.liveclient.LiveFeed. It speaks the official SignalR feed over a WebSocket implemented in the standard library — no websocket package, no SignalR client, no browser.

from f1verse.sources import liveclient

with liveclient.LiveFeed() as feed:
    for topic, patch, stamp in feed.messages():
        ...

liveclient.run("session-{n}.jsonl")   # record, rotate, reconnect

Connecting takes three undocumented courtesies: the load balancer issues its affinity cookie only to a pre-flight request and rejects sockets arriving without it, the service expects the official application's user agent, and a subscription sent without an invocation id is accepted silently and never answered. All three are handled here so no caller has to rediscover them.

Recordings carry a millisecond arrival stamp per frame, which is the difference between an archive and a screenshot — replay() can then run a session at true speed. Recordings are local working data; nothing is redistributed.

The raw stream is not a lap table. f1verse.sources.timing.laps_from_stream() rebuilds honest laps from it, because arrival order lies: sector times land after the next lap has begun, and qualifying carries phantom lap times that are really the gap between two runs.

Related