Skip to main content

Formula 1 Race Replay and Visualization Library

Project description

f1-replay

A Python wrapper around the FastF1 library for interactive Formula 1 race replays. View historic races in a 2D map visualization with real-time car positions using telemetry data.

Installation

pip install f1-replay

Or from source:

pip install -e .

Quick Start

from f1_replay import Manager

# Initialize manager
manager = Manager()

# Launch race replay viewer
manager.race(2024, "monaco")      # By event name
manager.race(2024, 8)             # By round number

This opens a Flask-based web viewer showing:

  • 2D track map with live car positions
  • Race progression with telemetry data
  • Driver information and timing

Usage

Browse Available Races

from f1_replay import Manager

manager = Manager()

# List available seasons
print(manager.list_years())

# Get season details
season = manager.get_season(2024)
for race in season.rounds:
    print(f"{race.round_number}. {race.event_name}")

Launch Race Viewer

# Multiple ways to select a race
manager.race(2024, 24)              # By round number
manager.race(2024, "abu dhabi")     # By event name (case-insensitive)
manager.race(2024, "monaco")        # Partial match works too

# Custom host/port
manager.race(2024, 8, host='localhost', port=8080)

# Force refresh data from FastF1
manager.race(2024, 8, force_update=True)

CLI Usage

# Launch race viewer
f1-replay race 2024 monaco
f1-replay race 2024 8 --port 8080

# List available races
f1-replay seasons
f1-replay seasons 2024

# Run standalone API server
f1-replay server --port 5000

Configuration

Set a global cache directory so f1-replay remembers where your data is stored:

# Set global cache directory (persists across sessions)
f1-replay config --set-cache-dir /path/to/race_data

# View current configuration
f1-replay config

Or set it in Python:

from f1_replay import set_cache_dir

set_cache_dir("/path/to/race_data")  # Persists globally

Or use an environment variable (takes priority over config file):

export F1_REPLAY_CACHE_DIR=/path/to/race_data

Priority: Environment variable > Config file > Default (./race_data)

Config file: ~/.f1replay/config.json

Features

  • Interactive 2D race replay with car positions
  • Telemetry-based animation using FastF1 data
  • Support for all session types (Race, Qualifying, Practice, Sprint)
  • Automatic data caching for fast loading
  • Event name or round number lookup

Requirements

  • Python 3.9+
  • FastF1
  • Flask

Advanced Usage

Direct Data Access

For custom analysis or building your own visualizations:

from f1_replay import Manager

manager = Manager()

# Load session data directly
session = manager.load_race(2024, "monaco")

# Access telemetry
telemetry = session.telemetry["VER"]  # Polars DataFrame
print(f"Telemetry points: {len(telemetry)}")

# Access track geometry
track = session.weekend.track
pit_lane = session.weekend.pit_lane

# Access events and results
weather = session.weather
fastest_laps = session.fastest_laps

Data Loading (DataLoader)

For more control over data loading:

from f1_replay.data_loader import DataLoader

loader = DataLoader(cache_dir="race_data")

# TIER 1: Season catalog
seasons = loader.load_seasons()

# TIER 2: Weekend data (circuit geometry)
weekend = loader.load_weekend(2024, 8)
print(f"Track length: {weekend.circuit.circuit_length:.0f}m")

# TIER 3: Session data (telemetry, events, results)
race = loader.load_session(2024, 8, "Race")

Cache Structure

Data is cached to disk for fast subsequent loads:

race_data/
├── seasons.pkl
└── 2024/
    ├── 08_Monaco/
    │   ├── Weekend.pkl    # Circuit + metadata
    │   └── R.pkl          # Race telemetry
    └── ...

Data Models

TIER 1: F1Seasons - Season catalog with race schedule

TIER 2: F1Weekend - Circuit geometry, pit lane, track segments

TIER 3: SessionData - Telemetry (Polars), events, results per driver

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

f1_replay-0.1.3.tar.gz (53.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

f1_replay-0.1.3-py3-none-any.whl (62.5 kB view details)

Uploaded Python 3

File details

Details for the file f1_replay-0.1.3.tar.gz.

File metadata

  • Download URL: f1_replay-0.1.3.tar.gz
  • Upload date:
  • Size: 53.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for f1_replay-0.1.3.tar.gz
Algorithm Hash digest
SHA256 410e017f7fca4e273603b36704f96804733e40c992b39671b95d6ebe3b9a7df2
MD5 1fef89594de74a2500db8535f6c5dedd
BLAKE2b-256 f466efc460f750385b91ddf83128def922245bf81dffe511768dd2395338290a

See more details on using hashes here.

File details

Details for the file f1_replay-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: f1_replay-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 62.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for f1_replay-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4410dd2e181f9730a36efc9b69d0e53438a3ebd633de5c82c4dfeb843a06b297
MD5 53f5f123419ebcb8ba5bd13f025c9a8a
BLAKE2b-256 032827851112eff30a21cd906d90201235196010b39947fc5625439ff2d92ff2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page