Always enable the cache before loading any data to improve performance and avoid rate limits.
import fastf1# Enable cache - replace with your preferred directoryfastf1.Cache.enable_cache('~/fastf1_cache')
Call Cache.enable_cache() immediately after imports and before any other FastF1 functionality.
2
Load a session
Use get_session() to create a session object, then call load() to fetch the data.
# Get the 2023 Azerbaijan Grand Prix Race sessionsession = fastf1.get_session(2023, 'Azerbaijan', 'R')# Load all session data (timing, telemetry, weather, etc.)session.load()
Session identifiers can be: 'FP1', 'FP2', 'FP3', 'Q' (Qualifying), 'S' (Sprint), 'SQ' (Sprint Qualifying), or 'R' (Race).
3
Access lap data
The session.laps DataFrame contains all lap information for all drivers.
# Get all laps for a specific driveralonso_laps = session.laps.pick_drivers('ALO')# Filter for quick laps only (removes outliers)quick_laps = alonso_laps.pick_quicklaps()# Get the fastest lapfastest_lap = alonso_laps.pick_fastest()print(f"Fastest lap time: {fastest_lap['LapTime']}")print(f"Lap number: {fastest_lap['LapNumber']}")print(f"Compound: {fastest_lap['Compound']}")
4
Access telemetry data
Retrieve high-frequency telemetry data for individual laps.
# Get telemetry for the fastest laptelemetry = fastest_lap.get_car_data()# Add distance column for easier analysistelemetry = telemetry.add_distance()# Access telemetry channelsprint(telemetry[['Distance', 'Speed', 'Throttle', 'Brake', 'nGear']].head())
Here’s a complete example that loads a session and analyzes driver lap times:
import fastf1import pandas as pd# Configure cachefastf1.Cache.enable_cache('~/fastf1_cache')# Load sessionsession = fastf1.get_session(2023, 'Azerbaijan', 'R')session.load()# Get laps for a driverdriver_laps = session.laps.pick_drivers('ALO').pick_quicklaps()# Display lap time statisticsprint(f"Total laps: {len(driver_laps)}")print(f"Fastest lap: {driver_laps['LapTime'].min()}")print(f"Average lap time: {driver_laps['LapTime'].mean()}")# Show compound usagecompound_usage = driver_laps.groupby('Compound').size()print(f"\nCompound usage:\n{compound_usage}")
# Multiple driverslaps = session.laps.pick_drivers(['HAM', 'VER', 'LEC'])# Specific lap numberlap_1 = session.laps.pick_laps(1)# Fastest lap per driverfastest_laps = session.laps.pick_fastest()# Laps on a specific compoundsoft_laps = session.laps[session.laps['Compound'] == 'SOFT']
Always enable caching - The first load will download data, but subsequent loads will be nearly instantaneous.
Use pick methods - Methods like pick_drivers(), pick_fastest(), and pick_quicklaps() are optimized for filtering lap data.
Load only what you need - If you only need timing data, you can skip telemetry by using session.load(telemetry=False, weather=False) for faster loading.