Python: read one timing snapshot
Install httpx and set F1_API_KEY in your environment. Register your device using the device setup guide and set F1_DEVICE_TRACK_ID to that same private identifier. Keep the generated stream UUID stable for the lifetime of this polling client.
import os, uuid, httpx
headers = {
"X-API-Key": os.environ["F1_API_KEY"],
"X-Device-Track-ID": os.environ["F1_DEVICE_TRACK_ID"],
"X-Stream-ID": str(uuid.uuid4()),
}
with httpx.Client(timeout=15) as client:
response = client.get(
"https://web.f1.kai-young.co.uk/api/v1/live/state",
headers=headers,
params={"session": "current"},
)
response.raise_for_status()
state = response.json()
print(state.get("mode"), state.get("notice"))
for driver in state.get("drivers", []):
print(driver.get("position"), driver.get("name"), driver.get("bestLap"))Python: consume server-sent events
Close your web timing page before starting this client. An occupied account slot returns HTTP 409.
import os, json, httpx
url = "https://web.f1.kai-young.co.uk/api/v1/live/stream"
with httpx.Client(timeout=30) as client:
with client.stream("GET", url,
headers={"X-API-Key": os.environ["F1_API_KEY"],
"X-Device-Track-ID": os.environ["F1_DEVICE_TRACK_ID"]},
params={"session": "current"}) as response:
response.raise_for_status()
for line in response.iter_lines():
if line.startswith("data: "):
state = json.loads(line[6:])
print(state.get("mode"), state.get("updatedAt"))For a long-running client, handle disconnections and retry with a delay. Check the mode and age of observations before labelling values as live.
Historical replay workflow
- Read
/api/v1/live/sessionsand choose a completed session ID. - Read its state to start loading the recording. A loading response means acquisition is still in progress.
- Read
/api/v1/live/replay?session=SESSION_IDto obtain coverage. - Request state with
sessionand a timezone-awareattimestamp within coverage.
Reuse your polling client UUID throughout. One-second playback holds the last recorded observation between updates.