Documentation Index
Fetch the complete documentation index at: https://mintlify.com/TracingInsights/tif1/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The tif1 library provides powerful methods for analyzing fastest laps, comparing drivers, and accessing fastest lap telemetry. This guide covers all fastest lap functionality.
Get Fastest Lap Per Driver
Retrieve the fastest lap for each driver in a session:
import tif1
session = tif1.get_session(2025, "Abu Dhabi Grand Prix", "Qualifying")
# Get fastest lap per driver
fastest_by_driver = session.get_fastest_laps(by_driver=True)
# Sort by lap time
fastest_by_driver = fastest_by_driver.sort_values("LapTime")
print(fastest_by_driver[["Driver", "Team", "LapTime", "Compound"]].head(10))
Output:
Driver Team LapTime Compound
VER Red Bull Racing 82.345 SOFT
LEC Ferrari 82.567 SOFT
HAM Mercedes 82.712 SOFT
...
Get Overall Fastest Lap
Retrieve the single fastest lap from the entire session:
# Get overall fastest lap
overall_fastest = session.get_fastest_laps(by_driver=False)
if len(overall_fastest) > 0:
driver = overall_fastest["Driver"].iloc[0]
team = overall_fastest["Team"].iloc[0]
lap_time = overall_fastest["LapTime"].iloc[0]
compound = overall_fastest["Compound"].iloc[0]
print(f"Fastest lap: {driver} ({team})")
print(f"Time: {lap_time:.3f}s on {compound} tires")
Get Driver’s Fastest Lap
Access the fastest lap for a specific driver:
# Get driver object
ver = session.get_driver("VER")
# Get driver's fastest lap
ver_fastest = ver.get_fastest_lap()
if len(ver_fastest) > 0:
lap_time = ver_fastest["LapTime"].iloc[0]
lap_num = ver_fastest["LapNumber"].iloc[0]
compound = ver_fastest["Compound"].iloc[0]
print(f"VER fastest lap:")
print(f" Lap Number: {lap_num}")
print(f" Time: {lap_time:.3f}s")
print(f" Compound: {compound}")
Filter by Specific Drivers
Get fastest laps for a subset of drivers:
# Get fastest laps for specific drivers
top_3_drivers = session.get_fastest_laps(
by_driver=True,
drivers=["VER", "HAM", "LEC"]
)
print("Top 3 drivers comparison:")
for _, row in top_3_drivers.iterrows():
print(f"{row['Driver']:3s}: {row['LapTime']:.3f}s ({row['Compound']})")
Compare Teammates
Analyze performance differences between teammates:
try:
# Get both Mercedes drivers
ham = session.get_driver("HAM")
rus = session.get_driver("RUS")
ham_fastest = ham.get_fastest_lap()
rus_fastest = rus.get_fastest_lap()
if len(ham_fastest) > 0 and len(rus_fastest) > 0:
ham_time = ham_fastest["LapTime"].iloc[0]
rus_time = rus_fastest["LapTime"].iloc[0]
delta = abs(ham_time - rus_time)
faster = "HAM" if ham_time < rus_time else "RUS"
print("Mercedes Teammate Comparison:")
print(f" HAM: {ham_time:.3f}s")
print(f" RUS: {rus_time:.3f}s")
print(f" Delta: {delta:.3f}s ({faster} faster)")
except tif1.DriverNotFoundError as e:
print(f"Driver not found: {e}")
Get Fastest Lap Telemetry
Access telemetry data for fastest laps:
# Get overall fastest lap telemetry
fastest_tel = session.get_fastest_lap_tel()
print(f"Fastest lap telemetry: {len(fastest_tel)} points")
print(f"Max speed: {fastest_tel['Speed'].max():.1f} km/h")
print(f"Max RPM: {fastest_tel['RPM'].max():.0f}")
Get Driver’s Fastest Lap Telemetry
# Get specific driver's fastest lap telemetry
ver = session.get_driver("VER")
ver_tel = ver.get_fastest_lap_tel()
print(f"VER fastest lap telemetry:")
print(f" Points: {len(ver_tel)}")
print(f" Max speed: {ver_tel['Speed'].max():.1f} km/h")
print(f" Max throttle: {ver_tel['Throttle'].max():.1f}%")
Parallel Telemetry Fetching
For performance-critical applications, fetch telemetry for multiple drivers in parallel:
import time
# Get all drivers' fastest lap telemetry (parallel!)
start = time.time()
all_fastest_tels = session.get_fastest_laps_tels(by_driver=True)
elapsed = time.time() - start
num_drivers = len(all_fastest_tels["Driver"].unique())
print(f"Fetched {num_drivers} drivers in {elapsed:.2f}s")
print(f"Average: {elapsed / num_drivers:.3f}s per driver")
Fetch Specific Drivers’ Telemetry
# Get telemetry for specific drivers (parallel)
top3_tels = session.get_fastest_laps_tels(
by_driver=True,
drivers=["VER", "HAM", "LEC"]
)
print(f"Drivers: {list(top3_tels['Driver'].unique())}")
print(f"Total telemetry points: {len(top3_tels):,}")
Top 3 Comparison
Analyze and compare the top 3 fastest drivers:
fastest_by_driver = session.get_fastest_laps(by_driver=True)
fastest_by_driver = fastest_by_driver.sort_values("LapTime")
if len(fastest_by_driver) >= 3:
print("Top 3 Comparison:")
top3 = fastest_by_driver.head(3)
for idx, row in top3.iterrows():
print(f"{row['Driver']:3s} ({row['Team']:20s}): {row['LapTime']:.3f}s")
# Calculate gaps
pole_time = top3["LapTime"].iloc[0]
for idx, row in top3.iloc[1:].iterrows():
gap = row["LapTime"] - pole_time
print(f" {row['Driver']} gap to pole: +{gap:.3f}s")
Speed Comparison Across Drivers
Compare maximum speeds from fastest lap telemetry:
# Get all fastest lap telemetry
all_fastest_tels = session.get_fastest_laps_tels(by_driver=True)
# Compare max speeds
speed_comparison = (
all_fastest_tels.groupby("Driver")["Speed"]
.max()
.sort_values(ascending=False)
.head(5)
)
print("Top 5 Max Speeds:")
for driver, speed in speed_comparison.items():
print(f" {driver}: {speed:.1f} km/h")
Sector Time Analysis
Analyze sector times from fastest laps:
fastest_by_driver = session.get_fastest_laps(by_driver=True)
# Filter drivers with complete sector times
valid_sectors = fastest_by_driver[
fastest_by_driver["Sector1Time"].notna() &
fastest_by_driver["Sector2Time"].notna() &
fastest_by_driver["Sector3Time"].notna()
]
# Find fastest sector times
print("Fastest Sector Times:")
for sector in [1, 2, 3]:
col = f"Sector{sector}Time"
fastest_idx = valid_sectors[col].idxmin()
driver = valid_sectors.loc[fastest_idx, "Driver"]
time = valid_sectors.loc[fastest_idx, col]
print(f" Sector {sector}: {driver} - {time:.3f}s")
Error Handling
Always handle cases where drivers or laps might not exist:
try:
ver = session.get_driver("VER")
ver_fastest = ver.get_fastest_lap()
if len(ver_fastest) > 0:
lap_time = ver_fastest["LapTime"].iloc[0]
print(f"VER fastest: {lap_time:.3f}s")
else:
print("VER has no valid laps")
except tif1.DriverNotFoundError:
print("VER not in this session")
Complete Example
Here’s a complete fastest laps analysis workflow:
import tif1
# Load qualifying session
session = tif1.get_session(2025, "Abu Dhabi Grand Prix", "Qualifying")
print("FASTEST LAPS ANALYSIS")
print("=" * 60)
# 1. Get fastest lap per driver
fastest_by_driver = session.get_fastest_laps(by_driver=True)
fastest_by_driver = fastest_by_driver.sort_values("LapTime")
print("\n1. FASTEST LAP PER DRIVER")
print(fastest_by_driver[["Driver", "Team", "LapTime", "Compound"]].head(10))
# 2. Overall fastest
overall_fastest = session.get_fastest_laps(by_driver=False)
driver = overall_fastest["Driver"].iloc[0]
lap_time = overall_fastest["LapTime"].iloc[0]
print(f"\n2. OVERALL FASTEST: {driver} - {lap_time:.3f}s")
# 3. Teammate comparison
try:
ham = session.get_driver("HAM")
rus = session.get_driver("RUS")
ham_time = ham.get_fastest_lap()["LapTime"].iloc[0]
rus_time = rus.get_fastest_lap()["LapTime"].iloc[0]
delta = abs(ham_time - rus_time)
print(f"\n3. MERCEDES COMPARISON")
print(f" HAM: {ham_time:.3f}s")
print(f" RUS: {rus_time:.3f}s")
print(f" Delta: {delta:.3f}s")
except tif1.DriverNotFoundError:
print("\n3. Mercedes drivers not found")
# 4. Telemetry analysis
fastest_tel = session.get_fastest_lap_tel()
print(f"\n4. FASTEST LAP TELEMETRY")
print(f" Max speed: {fastest_tel['Speed'].max():.1f} km/h")
print(f" Max RPM: {fastest_tel['RPM'].max():.0f}")
Next Steps