Skip to content

API: session_loader

load_session(year, gp, session, *, cache='.fastf1')

Load a FastF1 session with optional local cache directory.

Source code in src/fastf1_analytics/session_loader.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
def load_session(
    year: int,
    gp: str,
    session: str,
    *,
    cache: str | None = ".fastf1",
) -> Any:
    """Load a FastF1 session with optional local cache directory."""
    if cache:
        cache_path = Path(cache)
        cache_path.mkdir(parents=True, exist_ok=True)  # ensure cache dir exists
        fastf1.Cache.enable_cache(str(cache_path))
    s = fastf1.get_session(year, gp, session)
    s.load()
    return s

Example

from fastf1_analytics.session_loader import load_session
session = load_session(2024, "Monaco", "R", cache=".fastf1-cache")
print(session.event["EventName"], session.name)