Skip to main content
The laptimes.py script fetches detailed lap-by-lap timing data for each driver in a race.

Script Overview

Location: ~/workspace/source/laptimes.py The script:
  1. Fetches lap times using pagination (API returns max 100 records per request)
  2. Combines all paginated data into a single file
  3. Respects rate limits during pagination
  4. Saves complete lap timing data
Lap time data is available from 1996 onwards. Earlier races do not have lap-by-lap timing information.

API Endpoint with Pagination

The API paginates lap times because races can have thousands of individual lap records (number of drivers × number of laps).

Key Configuration

Fetch Function with Pagination

Races with many laps and many drivers can require 10+ paginated requests. The script automatically handles this but may take some time to complete.

Save Function

Main Function

Output Structure

Stored at: {year}/{race-name}/laptimes.json

Data Structure

Each lap contains: Each timing entry contains:

Usage Example

Single Race

Multiple Races

Pagination Example

For a typical modern F1 race:
  • 20 drivers × 60 laps = 1,200 lap time records
  • At 100 records per request = 12 API requests
  • At 4 requests/second = ~3 seconds per race

Performance Tips

The script automatically sleeps between requests to respect rate limits. Fetching lap times for an entire season may take several minutes.

Optimizing for Multiple Races

Data Availability

Lap time data is only available from 1996 onwards. Attempting to fetch lap times for earlier years will return empty results.

Logging

Pitstops

Collect pit stop data next (2011+)

Race Results

Compare with race finishing positions