Skip to main content
The core module is the heart of tif1, providing the primary interface for loading and working with Formula 1 data. All data access flows through the Session object, which serves as the central hub for accessing laps, telemetry, weather, race control messages, and driver information. The API is designed for maximum performance with async support, intelligent caching, and lazy loading patterns.

Overview

The core API is built around a hierarchical data model that mirrors the structure of Formula 1 sessions:
Key Design Principles:
  • Lazy Loading: Data is fetched only when accessed, minimizing unnecessary network requests. Properties like session.laps, session.weather, and lap.telemetry trigger data loading on first access.
  • Intelligent Caching: Multi-layer caching strategy with in-memory LRU cache (instant access) and SQLite persistent cache (survives restarts). Cache keys are session-specific and backend-aware (pandas vs polars).
  • Async Support: All data-intensive operations have async variants (laps_async(), get_fastest_laps_tels_async()) that use parallel HTTP requests for 4-5x faster loading compared to sequential access.
  • Backend Flexibility: Choose between pandas (default, maximum compatibility) or polars (faster for large datasets, 10-100x speedup for some operations) for DataFrame operations. Backend selection is per-session and affects all data structures.
  • FastF1 Compatibility: Drop-in replacement for FastF1 with the same API surface. All FastF1 methods (pick_driver(), pick_fastest(), iterlaps(), etc.) are supported with identical behavior.
  • Ultra-Cold Mode: Special optimization mode that bypasses cache validation and skips loading unnecessary data for minimal latency. Ideal for serverless environments or when you only need specific data (e.g., fastest lap telemetry).
  • Error Resilience: Comprehensive exception hierarchy (DataNotFoundError, NetworkError, InvalidDataError) with structured error context. Failed telemetry fetches are tracked per-driver to avoid repeated failures.
Performance Characteristics: Memory Footprint:
  • Session metadata: ~10-50 KB
  • Laps DataFrame (20 drivers, 60 laps): ~500 KB - 2 MB
  • Single lap telemetry: ~50-200 KB (varies by track length)
  • Full session telemetry (all laps): ~50-200 MB (rarely needed)
Thread Safety:
  • Session objects are thread-safe for read operations
  • Internal caches use threading locks for concurrent access
  • Async methods can be called from multiple coroutines safely

get_session

The main entry point for loading F1 session data. This function handles event name resolution, session validation, and returns a configured Session object ready to load data.
Parameters:
int
required
Season year (2018-current). Must be within the supported range.Valid range: 2018 to current seasonExample: 2024, 2025
str | int
required
Grand Prix identifier. Can be specified in multiple ways:
  • Full name: "Monaco Grand Prix", "British Grand Prix"
  • Abbreviated name: "Monaco", "Silverstone" (uses fuzzy matching)
  • Round number: 6, 12 (1-indexed, based on calendar order)
The function automatically resolves abbreviated names and round numbers to the official event name.Example: "Monaco Grand Prix", "Monaco", 6
str | int
required
Session identifier. Can be specified as:
  • Full name: "Practice 1", "Qualifying", "Race"
  • Abbreviated: "FP1", "FP2", "FP3", "Q", "S" (Sprint), "R"
  • Session number: 1 (Practice 1), 2 (Practice 2), 3 (Practice 3), 4 (Qualifying), 5 (Race)
Session numbers are 1-indexed and follow the weekend schedule order.Example: "Qualifying", "Q", 4
bool | None
default:"None"
Enable or disable caching for this session.
  • True: Enable caching (recommended for production)
  • False: Disable caching (useful for testing or forcing fresh data)
  • None: Use global config value (default behavior)
Caching behavior: When enabled, all fetched data (laps, telemetry, weather, messages) is stored in a local SQLite database. Subsequent access to the same data reads from cache instead of making network requests.Cache location: ~/.tif1/cache/tif1_cache.db
Literal['pandas', 'polars'] | None
default:"None"
DataFrame library choice for data representation.
  • "pandas": Use pandas DataFrames (default, maximum compatibility)
  • "polars": Use polars DataFrames (faster for large datasets, requires polars package)
  • None: Use global config value (defaults to "pandas")
Performance note: Polars can be significantly faster for large datasets (10-100x for some operations), but requires the polars package to be installed. If polars is requested but not available, tif1 automatically falls back to pandas with a warning.
Returns:
Session
A configured Session object ready to load data. The session is not loaded until you access its properties (lazy loading) or explicitly call session.load().
Raises:
Exception
Raised in the following cases:
  • Year is outside the supported range (< 2018 or > current season)
  • Grand Prix name/round cannot be resolved
  • Session name/number doesn’t exist for the specified event
  • Session number is out of range for the event
Exception
Raised when the specified year, GP, or session doesn’t exist in the data source.
Exception
Raised when all CDN sources fail to respond or return errors.
Examples:
Best Practice: Use abbreviated names and session codes for cleaner code:
Event Name Resolution: The function uses fuzzy matching to resolve abbreviated event names. For example, "Silverstone" resolves to "British Grand Prix", and "Spa" resolves to "Belgian Grand Prix". If fuzzy matching fails, the original string is used as-is.

Session

The Session object is the central hub for all data related to a specific F1 weekend session. It provides access to lap timing data, telemetry, weather conditions, race control messages, driver information, and session results. Design Philosophy:
  • Lazy Loading: Properties are loaded on first access, not at construction time
  • Caching: All fetched data is cached (when enabled) to minimize network requests
  • Immutable Identity: Once created, a session’s year/GP/session cannot be changed
  • Thread-Safe: Internal caches use locks for concurrent access
  • Memory Efficient: Only requested data is loaded into memory

Constructor

Direct Construction Not Recommended: Use get_session() instead of constructing Session directly. The get_session() function handles name normalization, validation, and ensures the session exists before creating the object.
Constructor Parameters:
int
required
Season year (2018-current). Must be within the supported range.
str
required
URL-encoded Grand Prix name (e.g., "Monaco_Grand_Prix"). Spaces should be replaced with underscores or %20.Note: get_session() handles this encoding automatically.
str
required
URL-encoded session name (e.g., "Qualifying", "Race").
bool | None
default:"None"
Enable/disable caching. If None, uses global config value.
Literal['pandas', 'polars'] | None
default:"None"
DataFrame library choice. If None, uses global config value (defaults to "pandas").

Properties

int
The season year (e.g., 2025).
str
URL-encoded Grand Prix name (e.g., “Monaco_Grand_Prix”).
str
URL-encoded session name (e.g., “Qualifying”, “Race”).
Literal['pandas', 'polars']
The DataFrame lib being used for this session.
bool
Whether caching is enabled for this session.
list[str]
List of driver numbers as strings in the session (e.g., [“1”, “33”, “44”]). Loaded lazily on first access.
This returns driver NUMBERS, not driver codes. For driver codes (e.g., “VER”, “HAM”), use drivers_df["Driver"].
list[str]
Alias for drivers property. Returns driver numbers as strings.
DataFrame
DataFrame with driver information including:
  • Abbreviation: 3-letter driver code (e.g., “VER”, “HAM”)
  • TeamName: Team name
  • DriverNumber: Car number as string
  • FirstName: Driver’s first name
  • LastName: Driver’s last name
  • FullName: Full name (FirstName + LastName)
  • TeamColor: Hex color code
  • HeadshotUrl: URL to driver photo
Loaded lazily on first access.
DataFrame
All laps for all drivers. Includes weather data automatically merged. Loaded lazily on first access. Use laps_async() for faster parallel loading.
DataFrame
Weather data recorded during the session with columns:
  • Time: Timestamp
  • AirTemp: Air temperature (°C)
  • TrackTemp: Track temperature (°C)
  • Humidity: Relative humidity (%)
  • Pressure: Atmospheric pressure (mbar)
  • WindSpeed: Wind speed (km/h)
  • WindDirection: Wind direction (degrees)
  • Rainfall: Rainfall indicator
DataFrame
Alias for weather property.
DataFrame
Official messages from Race Control with columns:
  • Time: Message timestamp
  • Category: Message category (e.g., “Flag”, “SafetyCar”)
  • Message: Message text
  • Status: Track status code
  • Flag: Flag type
  • Scope: Message scope
  • Sector: Affected sector
  • RacingNumber: Affected driver number
SessionResults
Final classification/results for the session. Contains:
  • Position: Final position
  • Driver: Driver code
  • Team: Team name
  • Points: Championship points earned
  • Status: Finish status
  • Time: Total time or gap
DataFrame
Car telemetry data aggregated across all laps with columns:
  • Time: Timestamp
  • Speed: Speed (km/h)
  • RPM: Engine RPM
  • nGear: Gear number
  • Throttle: Throttle position (%)
  • Brake: Brake status
  • DRS: DRS status
DataFrame
Position data for all cars with columns:
  • Time: Timestamp
  • X, Y, Z: 3D coordinates (meters)
  • Status: Car status
  • Driver: Driver code
dict
Session metadata including start time, circuit info, and session status.
str
Human-readable session name (e.g., “Monaco Grand Prix - Qualifying”).
datetime
Session date and time.
dict
Event information including circuit details and schedule.
datetime
Official session start time.
datetime
Reference time (t=0) for the session.
list
Session status changes throughout the session.
DataFrame
Track status changes (flags, safety car, etc.) with timestamps.
int | None
Total number of laps completed in the session.
This property is not yet implemented and currently returns None.

Methods

load()

Explicitly load session data. By default, data is loaded lazily when accessed. Parameters:
  • laps: Load lap timing data
  • telemetry: Prefetch telemetry for all laps (expensive)
  • weather: Load weather data
  • messages: Load race control messages
Returns:
  • Self (for method chaining)
Example:

laps_async()

Asynchronously load all laps for all drivers using parallel HTTP requests. This is the fastest way to initialize a session. Returns:
  • DataFrame with all laps
Example:

get_driver()

Get a Driver object for the specified driver. Parameters:
  • driver: 3-letter driver code (e.g., “VER”) or driver number (e.g., 33)
Returns:
  • Driver object
Raises:
  • DriverNotFoundError: If the driver doesn’t exist in this session
Example:

get_fastest_laps()

Get the fastest lap(s) from the session. Parameters:
  • by_driver: If True, returns fastest lap per driver. If False, returns single overall fastest lap
  • drivers: Optional list of driver codes to filter. If None, includes all drivers
Returns:
  • DataFrame with fastest lap(s)
Example:

get_fastest_laps_async()

Async version of get_fastest_laps() for parallel data fetching.

get_fastest_lap_tel()

Optimized method to get telemetry for the single overall fastest lap of the session. Uses ultra-cold start optimization to minimize latency. Parameters:
  • ultra_cold: Enable ultra-low latency mode. If None, uses global config
Returns:
  • DataFrame with telemetry data
Example:

get_fastest_lap_tel_async()

Async version of get_fastest_lap_tel().

get_fastest_laps_tels()

Parallel fetch telemetry for multiple drivers’ fastest laps. Significantly faster than fetching telemetry sequentially. Parameters:
  • by_driver: If True, gets fastest lap per driver. If False, gets overall fastest
  • drivers: Optional list of driver codes to filter
  • ultra_cold: Enable ultra-low latency mode
Returns:
  • Dictionary mapping driver codes to telemetry DataFrames
Example:
Performance Tip: This method fetches telemetry for multiple drivers in parallel, which is significantly faster than calling get_fastest_lap_tel() sequentially for each driver.

get_fastest_laps_tels_async()

Async version of get_fastest_laps_tels().

fetch_driver_laps_parallel()

Fetch lap data for multiple drivers in parallel. Parameters:
  • drivers: List of driver codes
Returns:
  • Dictionary mapping driver codes to lap DataFrames
Example:

fetch_all_laps_telemetry()

Fetch telemetry for all laps of specified drivers synchronously. Parameters:
  • drivers: Optional list of driver codes. If None, fetches for all drivers
  • ultra_cold: Enable ultra-low latency mode
Returns:
  • Dictionary mapping (driver, lap_number) tuples to telemetry DataFrames
Warning: This can be very slow and data-intensive (50-200 MB for full session). Use sparingly. Prefer the async version for better performance. Example:

fetch_all_laps_telemetry_async()

Async version of fetch_all_laps_telemetry(). Fetches telemetry for all laps in parallel, significantly faster than the sync version. Performance: 5-10x faster than sync version due to parallel HTTP requests. Example:
Memory Warning: Fetching all telemetry for a full race session can consume 50-200 MB of memory. Only use this when you genuinely need all telemetry data. For most use cases, fetch telemetry for specific laps or drivers instead.

get_circuit_info()

Get circuit information including track length and corner locations. Returns:
  • CircuitInfo object with:
    • corners: DataFrame with columns X, Y, Number, Letter, Angle, Distance
    • marshal_lights: Empty DataFrame (not available in data source)
    • marshal_sectors: Empty DataFrame (not available in data source)
    • rotation: Circuit rotation in degrees (float)
Caching: Results are cached on the session object after the first call. Example:
FastF1 Compatibility: This method returns a CircuitInfo dataclass that is fully compatible with FastF1’s mvapi.CircuitInfo. The add_marker_distance() method works identically to FastF1’s implementation.

Driver

Represents a specific driver’s performance within a session. Provides convenient access to driver-specific lap data and telemetry. The Driver class extends pd.Series, so driver metadata is accessible as Series data. Design Philosophy:
  • Lazy Loading: Lap data is loaded on first access to driver.laps
  • Efficient Filtering: When session laps are already loaded, driver laps are filtered in-place without additional network requests
  • Prefetching: The get_driver() method can prefetch driver laps in parallel with driver metadata for faster initialization
  • Caching: Lap index maps are cached for O(1) lap number lookups
Performance Characteristics:
  • First access to driver.laps: 200-500ms (cold cache), <50ms (warm cache)
  • Subsequent access: <1ms (in-memory reference)
  • get_lap(n): O(1) lookup using cached index map
  • get_fastest_lap(): O(n) scan of lap times (typically <1ms for 60 laps)

Constructor

Use session.get_driver() instead of constructing Driver directly. The Driver class extends pd.Series and contains driver metadata as Series data.

Properties

str
The 3-letter driver code (e.g., “VER”, “HAM”, “LEC”).
DataFrame
All laps completed by this driver. Loaded lazily on first access. Contains all lap timing data including sector times, compounds, stint info, etc.
Session
Reference to the parent session object.

Series Data

Since Driver extends pd.Series, driver metadata is accessed via dictionary-style indexing:
  • driver["DriverNumber"]: Car number as string (e.g., “33”, “44”, “16”)
  • driver["Abbreviation"]: 3-letter driver code (same as driver.driver)
  • driver["TeamName"]: Team name (e.g., “Red Bull Racing”, “Mercedes”)
  • driver["TeamColor"]: Hex color code
  • driver["FirstName"]: Driver’s first name
  • driver["LastName"]: Driver’s last name
  • driver["FullName"]: Full name (FirstName + LastName)
  • driver["HeadshotUrl"]: URL to driver photo

Methods

get_lap()

Get a specific lap by number. Parameters:
  • lap_number: The lap number to retrieve (1-indexed)
Returns:
  • Lap object for the specified lap
Raises:
  • LapNotFoundError: If the lap doesn’t exist for this driver
Example:

get_fastest_lap()

Get this driver’s fastest lap as a single-row DataFrame. Returns:
  • Single-row DataFrame with the fastest lap data
Example:

get_fastest_lap_tel()

Get telemetry for this driver’s fastest lap. Uses the session’s ultra-cold mode setting. Returns:
  • DataFrame with telemetry data (Time, Speed, RPM, Throttle, etc.)
Example:

Laps

The Laps class extends pd.DataFrame and provides a rich set of methods for filtering and analyzing lap timing data. It represents a collection of laps (either for all drivers or a specific driver) with FastF1-compatible filtering methods. Design Philosophy:
  • DataFrame Extension: Inherits all pandas DataFrame methods while adding F1-specific functionality
  • Method Chaining: Most methods return new Laps objects, enabling fluent API patterns
  • FastF1 Compatibility: All pick_* methods match FastF1’s behavior exactly
  • Lazy Telemetry: The telemetry property loads telemetry only when accessed

Filtering Methods

pick_driver(identifier) / pick_drivers(identifiers)

Filter laps by driver(s). Accepts driver codes, numbers, or driver objects.

pick_lap(lap_number) / pick_laps(laps)

Filter by lap number(s). Supports individual numbers, lists, or slices.

pick_team(name) / pick_teams(names)

Filter laps by team name(s).

pick_fastest(only_by_time=False)

Get the single fastest lap from the collection.
Returns: Single Lap object (pd.Series) or None if no valid laps.

pick_quicklaps(threshold=1.07)

Filter laps within a percentage of the fastest lap time. Default threshold is 107% (7% slower than fastest).
Use Case: Analyzing representative lap times, excluding outliers (slow laps, traffic, mistakes).

pick_tyre(compound) / pick_compounds(compounds)

Filter laps by tire compound.
Common Compounds: "SOFT", "MEDIUM", "HARD", "INTERMEDIATE", "WET"

pick_track_status(status, how="equals")

Filter laps by track status code.
Track Status Codes:
  • "1": Green flag (normal racing)
  • "2": Yellow flag
  • "4": Safety Car
  • "5": Red flag
  • "6": Virtual Safety Car (VSC)
  • "7": VSC ending
Parameters:
  • how="equals": Exact match (default)
  • how="contains": Partial match (useful for compound status codes)

pick_wo_box() / pick_box_laps(which="both")

Filter laps by pit stop activity.

pick_not_deleted() / pick_accurate()

Filter laps by data quality flags.

Data Access Methods

get_telemetry() / get_car_data() / get_pos_data()

Get telemetry data for the laps. All three methods return the same data (FastF1 compatibility).
Returns: Telemetry DataFrame with columns: Time, Speed, RPM, Throttle, Brake, nGear, DRS, X, Y, Z, Distance Note: Only works for single-driver laps. Raises ValueError if laps contain multiple drivers.

get_weather_data()

Get weather data for the session.
Returns: Weather DataFrame from the parent session.

split_qualifying_sessions()

Split qualifying laps into Q1, Q2, Q3 sessions.
Returns: Tuple of three Laps objects (Q1, Q2, Q3). If qualifying session markers are unavailable, returns three copies of the full laps DataFrame.

iterlaps(require=None)

Iterate over laps with optional column requirements. Yields (index, lap) tuples where lap is a Lap object.
Parameters:
  • require: Optional list of column names that must be non-null. Laps with null values in these columns are skipped.
Returns: Generator yielding _IterLapResult tuples with:
  • .index: DataFrame index of the lap
  • .lap: Lap object (pd.Series) with session reference
  • [column_name]: Direct column access (e.g., result["Driver"])
Performance: Efficient iteration with minimal memory overhead. Telemetry is loaded lazily per lap.

Utility Methods

reset_index(drop=False, **kwargs)

Reset DataFrame index. Automatically removes level_0 column if created.

Properties

telemetry

Get telemetry for all laps in the collection. Only works for single-driver laps.
Returns: Telemetry DataFrame (concatenated telemetry from all laps). Raises: ValueError if laps contain multiple drivers.

Example: Complex Filtering


Lap

Represents a single lap, providing access to high-frequency telemetry data. This is a lightweight wrapper around lap timing data with lazy telemetry loading. The Lap class extends pd.Series, so lap data is accessible as Series data.

Constructor

Use driver.get_lap() instead of constructing Lap directly.

Properties

int
The lap number (1-indexed). Access via lap.lap_number property.
str
The 3-letter driver code. Access via lap.driver property.
DataFrame
High-frequency telemetry data for this lap. Loaded lazily on first access. Contains Time, Speed, RPM, Throttle, Brake, nGear, DRS, and position data.
Session
Reference to the parent session object.

Series Data

Since Lap extends pd.Series, lap timing data is accessed via dictionary-style indexing or the get() method:
  • lap.get('LapTime'): Lap time as timedelta
  • lap.get('LapTimeSeconds'): Lap time in seconds as float
  • lap.get('LapNumber'): Lap number (same as lap.lap_number)
  • lap.get('Driver'): Driver code (same as lap.driver)
  • lap.get('Sector1Time'), lap.get('Sector2Time'), lap.get('Sector3Time'): Sector times
  • lap.get('Compound'): Tire compound
  • lap.get('TyreLife'): Tire age in laps
  • lap.get('IsPersonalBest'): Boolean indicating personal best lap

Methods

get_telemetry()

Explicitly load telemetry data. Same as accessing the telemetry property. Returns:
  • DataFrame with telemetry samples
Example:

get_car_data()

Get car telemetry data (Speed, RPM, Throttle, Brake, nGear, DRS). Returns:
  • DataFrame with car telemetry channels

get_pos_data()

Get position data (X, Y, Z coordinates). Returns:
  • DataFrame with position data

get_weather_data()

Get weather data for this lap. Returns:
  • DataFrame with weather information

Complete Examples

Basic session usage

Working with Drivers

Working with Telemetry

Available Telemetry Columns:
  • Time: Timestamp (timedelta)
  • Speed: Speed in km/h
  • RPM: Engine RPM
  • Throttle: Throttle position (0-100%)
  • Brake: Brake status (boolean or 0-100%)
  • nGear: Gear number
  • DRS: DRS status
  • X, Y, Z: 3D position coordinates (meters)
  • Distance: Distance along track (meters)

Parallel data loading

Performance Tip: laps_async() is significantly faster than the laps property for cold starts because it fetches all driver lap data in parallel. Use async methods when performance is critical.

Ultra-cold start mode

Ultra-cold mode bypasses cache validation and skips loading unnecessary data for faster cold starts. Use when you need minimal latency and don’t need all session data. The trade-off is that some data validation is skipped.

Error Handling

Performance Comparison

Best Practices:
  • Use async methods (laps_async(), get_fastest_laps_tels_async()) for cold starts
  • Enable caching to speed up subsequent loads
  • Use ultra_cold=True when you only need specific data
  • Filter drivers with the drivers parameter to reduce data transfer

Troubleshooting

Common Issues

Issue: DriverNotFoundError when using driver codes
Issue: LapNotFoundError when accessing laps
Issue: Empty telemetry data
Issue: Slow data loading

API Overview

Complete API map

Models

Data structures

Sessions Concept

Understanding sessions

Getting Started

Usage guide
Last modified on May 8, 2026