Skip to main content
The events.py script is the foundation of the data collection pipeline. It fetches the race calendar for each season and creates the directory structure for storing race data.

Script Overview

Location: ~/workspace/source/events.py The events script:
  1. Fetches the race calendar for specified seasons
  2. Creates year and race directories
  3. Saves event metadata for each race
  4. Stores the complete season calendar

API Endpoint

The script uses the Ergast API races endpoint:

Key Functions

Race Name Slugification

Converts race names to URL-friendly folder names:
Example:
  • “Belgian Grand Prix” → belgian-grand-prix
  • “Monaco Grand Prix” → monaco-grand-prix

Directory Creation

Rate-Limited Fetching

The script sleeps for 0.3 seconds between requests to stay within the 4 requests/second limit.

Main Process

The main function iterates through seasons and processes each race:

Output Structure

events.json (Season Calendar)

Stored at: {year}/events.json

event_info.json (Individual Race)

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

Usage Example

To fetch events for multiple seasons:
Modify the year range in the main() function:
Fetching data for all seasons (1950-2024) will make hundreds of API requests. Ensure you respect the rate limits to avoid being blocked.

Next Steps

After collecting events data, you can fetch:

Race Results

Fetch finishing positions and race outcomes

Qualifying

Collect qualifying session results