FastF1 Documentation

repository·main·Indexed 26 days ago

https://github.com/theoehrly/fast-f1

A Python library for accessing and analyzing Formula 1 results, schedules, timing data, and telemetry. It leverages Pandas DataFrames and Matplotlib for F1 data science and visualization, providing tools for session results, circuit information via the MV API, and historical data through the Jolpica-F1 (Ergast) API.

Tokens
20.4K
Snippets
17
Records
181
Agent score
87%

What's inside fastf1

  1. Overview of FastF1 features

    main

    FastF1 provides programmatic access to Formula 1 data, including lap timing, car telemetry, position, tyre data, weather data, event schedules, and session results.

    Key features include:

    • Pandas Integration: All data is provided as extended Pandas DataFrames, including custom functions specifically designed for F1 data manipulation.
    • Ergast Compatibility: Full support for the Ergast-compatible jolpica-f1 API for accessing current and historical data.
    • Visualization: Built-in integration with Matplotlib for data visualization.
    • Caching: Implements caching for all API requests to improve performance. Since sessions can involve large data chunks (50-100MB), caching is enabled by default using an OS-specific location. You can configure a custom cache location using fastf1.req.Cache.
  2. Understand FastF1 rate limiting and caching behavior

    main

    FastF1 uses a caching and rate limiting system for all HTTP requests.

    • Caching: Enabled by default. It speeds up programs by serving requests from local storage. Disabling it is highly discouraged as it significantly slows down execution.
    • Rate Limits: Applied to all HTTP requests. However, requests served from the cache do not count towards rate limits. Enabling the cache effectively increases your available rate limit.
    • Rate Limit Enforcement:
      • Soft limit: FastF1 will throttle the request rate by introducing small delays.
      • Hard limit: FastF1 will raise a fastf1.exceptions.RateLimitExceededError.
  3. Access available data in FastF1

    main

    The standard workflow in FastF1 is to create a fastf1.core.Session object using fastf1.get_session(). Most data is then accessed through this session object.

    Available data topics include:

    • Event Schedule: Event names, locations, and dates via fastf1.get_event_schedule or fastf1.get_event.
    • Results: Driver/team names, positions, and points via fastf1.core.SessionResults and fastf1.core.DriverResult.
    • Timing Data: Sector times, lap times, pit stops, and tyre data via fastf1.core.Session.laps (fastf1.core.Laps).
    • Track Status: Flags and safety car information via fastf1.core.Session.track_status.
    • Session Status: Whether a session started, finished, or finalized via fastf1.core.Session.session_status.
    • Race Control Messages: Investigations, penalties, and restarts via fastf1.core.Session.race_control_messages.
    • Telemetry: Speed, RPM, gear, and track position via fastf1.core.Telemetry or fastf1.core.Lap.get_car_data.
    • Track Markers: Corner numbers and marshall info via fastf1.core.Session.get_circuit_info.
    • Jolpica-F1 API: Access to all endpoints previously provided by Ergast.
  4. FastF1 API functional categories

    main

    The FastF1 API is categorized into the following functional areas to help you find the right tools for your task:

    • Functions: Data loading (loading_data) and data plotting (plotting_data).
    • Objects: Core data entities including events, session, timing_data, telemetry, results, and circuit_info.
    • External APIs: Integrations with jolpica and ergast.
    • Advanced Usage: Specialized modules for accounts_auth, cache_and_rate_limits, exceptions, logging, livetiming, utils, and deprecated_legacy features.
  5. Migrate from deprecated FastF1 APIs (v3.0.0+)

    main

    If you are upgrading to v3.0.0 or later, note the following breaking changes and removals:

    Function Replacements:

    • Use fastf1.get_session(identifier) instead of fastf1.core.get_session or fastf1.events.get_session. The event argument is replaced by identifier.
    • The strict_search parameter in fastf1.get_event can be used to disable fuzzy matching for session names.
    • fastf1.core.Session.load_laps() and fastf1.core.Session.load_telemetry() have been removed.

    Removed Properties/Classes:

    • fastf1.events.Event.name, .date, and .gp are removed.
    • fastf1.core.Session.weekend is removed.
    • fastf1.core.DriverResult properties .name, .familyname, .grid, .position, and .team are removed.
    • fastf1.core.Driver and fastf1.core.Weekend classes are removed.
    • fastf1.ergast.fetch_weekend is removed.

    Behavioral Changes:

    • fastf1.utils.to_datetime and fastf1.utils.to_timedelta now return None instead of raising an exception when a string cannot be parsed.
    • Sprint session names are now always 'Sprint' (previously 'Sprint Qualifying' for 2021).
  6. Get sprint qualifying data using get_session()

    main

    In version 2.1.8, temporary support was added for sprint qualifying sessions. To retrieve data for a sprint qualifying session, use the fastf1.get_session function and pass event='SQ' as an argument.

    Note for Sprint Weekends: On weekends featuring sprint qualifying, the session order changes:

    • FP2 occurs on Saturday.
    • FP3 does not exist.
  7. Load events and sessions by name or location

    main

    Instead of using round numbers, you can load events or sessions using descriptive names (e.g., 'French Grand Prix', 'Spain') or locations (e.g., 'Silverstone'). FastF1 performs a best-match search, so ensure names are precise to avoid incorrect matches (e.g., 'Emilian' might match 'Belgian Grand Prix' instead of 'Emilia Romagna').

    import fastf1
    
    # Load event by name
    event = fastf1.get_event(2021, 'French Grand Prix')
    
    # Load session by location and session type
    session = fastf1.get_session(2021, 'Silverstone', 'Q')
  8. Update data loading methods for Sessions

    main

    The method fastf1.core.Session.load_laps is deprecated. You should use fastf1.core.Session.load instead, which provides more flexibility for selecting data to load.

    Important: The new load method does not return a fastf1.core.Laps object. Instead, you should access laps via the fastf1.core.Session.laps attribute.

  9. Verify lap timing accuracy with IsAccurate

    main

    The IsAccurate boolean flag indicates if a lap's start and end times are correctly synced with other laps. A lap marked as IsAccurate == True has passed these criteria:

    • It is not an inlap or outlap.
    • It was set under green or yellow flag conditions.
    • It is not the first lap immediately following a safety car (SC/VSC) period.
    • It contains a valid LapTime and all SectorTime values.
    • The sum of the sector times matches the LapTime.

    Note: Laps marked as inaccurate should be handled with caution as they may contain errors that are difficult to detect.

  10. Update Python and dependency requirements for v3.8.0+

    main

    As of version 3.8.0, the minimum supported Python version is 3.10. Support for Python 3.9 has been dropped.

    Additionally, the following minimum dependency versions are required:

    • matplotlib>=3.8.0
    • numpy>=1.26.0
    • pandas>=2.1.1
    • requests>=2.30.0
    • scipy>=1.11.0
    • pydantic (new dependency)