laptimes.py
Thelaptimes.py script fetches complete lap-by-lap timing data for Formula 1 races. This includes every lap time for every driver in a race, which can result in large datasets requiring pagination.
Overview
This script:- Fetches lap times from the Ergast API with pagination
- Handles large datasets (races can have 800+ lap records)
- Implements rate limiting and retry logic
- Saves complete lap timing data to JSON files
Lap time data is available from 1996 onwards. Earlier seasons do not have lap timing information.
Functions
fetch_laptimes()
Fetches all lap times for a race using pagination.laptimes.py
year(int): F1 season yearround_num(int): Round number in the season
dict: Complete lap times data with all pages combined
- Fetches 100 records per request (LIMIT = 100)
- Automatically continues until all lap records are retrieved
- A typical race has 300-800 lap records
save_laptimes()
Saves lap times data to the appropriate directory.laptimes.py
main()
Main execution function.laptimes.py
Usage
Basic Usage
Command Line
API Endpoint
limit: Number of lap records per request (default: 100)offset: Starting position for pagination
Output Structure
Lap times are saved to:{year}/{race-slug}/laptimes.json
Configuration
Performance Considerations
Data Volume
A typical race has:- 50-70 laps per race
- 20 drivers on the grid
- ~1,000-1,400 lap records total
Request Count
With a limit of 100 records per request:- 10-14 API requests per race
- At 4 requests/second = ~3 seconds per race
- For a full season (24 races) = ~1 minute
Logging
Log file:laptimes_fetch.log