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.

Inspired by f1-race-replay by Tom Shaw. This project was built from scratch with a different architecture and feature set.

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.4.tar.gz (53.5 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.4-py3-none-any.whl (62.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: f1_replay-0.1.4.tar.gz
  • Upload date:
  • Size: 53.5 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.4.tar.gz
Algorithm Hash digest
SHA256 4c8afa3270e1dfeb32593c561d92fedcb9f5d392bae415aaa449f4ec066d5be5
MD5 5881461d792c2e315dd819ae13649ee6
BLAKE2b-256 c93e067490dae7629b7d1d8ce8ab3eacf48c1876550cec2e555491c54eb60812

See more details on using hashes here.

File details

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

File metadata

  • Download URL: f1_replay-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d987b41e388c607cd0a9b78055deea94340eb17a30e3002ee22ed37a2aa3452e
MD5 2c0e9627a3bd51912a86f812894e2320
BLAKE2b-256 020d17c51e28726e937e625e7560ac6facf3c2c0f98af6c9d219b875b5cfb836

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