Skip to main content

Formula 1 Race Replay and Visualization Library

Project description

f1-replay

PyPI version Python 3.9+ License: MIT

A Python toolkit for Formula 1 data analysis and visualization. Built on FastF1 with intelligent caching, schedule tools, circuit plotting, and live race replay.

Installation

pip install f1-replay

Features

  • 3-Tier Data Management — Hierarchical caching system for seasons, weekends, and sessions
  • F1 Info Tools — Query schedules, browse events, and resolve races by name or round
  • Circuit Plotting — Poster-style track maps with sector coloring and telemetry overlays
  • Race Replay — Interactive 2D visualization with real-time car positions

Quick Start

from f1_replay import Manager

manager = Manager()

# Launch interactive race replay
manager.race(2024, "monaco")

# Browse available races
manager.season_schedule(2024)

Data Management

Intelligent 3-tier caching system that minimizes API calls and enables fast data access.

Tier 1: Seasons Catalog

manager.list_years()           # Available seasons
manager.get_season(2024)       # All events for a year

Tier 2: Weekend Data

weekend = manager.load_weekend(2024, "monaco")

weekend.circuit.track          # Track geometry (x, y, z)
weekend.circuit.pit_lane       # Pit lane coordinates
weekend.circuit.corners        # Corner positions and numbers

Tier 3: Session Telemetry

session = manager.load_session(2024, "monaco", "Race")

session.telemetry["VER"]       # Polars DataFrame with full telemetry
session.drivers                # ["VER", "NOR", "LEC", ...]
session.driver_colors          # {"VER": "#3671C6", ...}
session.track_status           # Yellow flags, safety cars, etc.
session.race_control           # Race control messages

Telemetry columns: session_time, x, y, z, speed, throttle, brake, rpm, gear, drs, lap_number, compound, tyre_life, track_distance


F1 Info Tools

Query schedules and find events with flexible resolution.

# Schedule queries
manager.season_schedule(2024)      # Full season overview
manager.race_schedule(2024)        # Race sessions only
manager.sprint_schedule(2024)      # Sprint weekends
manager.qualification_schedule(2024)
manager.practice_schedule(2024)

# Flexible event lookup
manager.load_weekend(2024, 8)           # By round number
manager.load_weekend(2024, "monaco")    # By name (case-insensitive)
manager.load_weekend(2024, "abu dhabi") # Partial match supported

Circuit Plotting

Generate poster-style circuit maps with customizable visualization.

from f1_replay.tools import plot_weekend

weekend = manager.load_weekend(2024, "monaco")

# Clean white track
plot_weekend(weekend.circuit, weekend.event)

# Colored by marshal sectors
plot_weekend(weekend.circuit, weekend.event, color_mode='sectors')

# Telemetry overlay (requires session data)
plot_weekend(weekend.circuit, weekend.event, color_mode='speed')

Color modes: white, sectors, speed, throttle, brake, height


Race Replay

Launch an interactive web viewer with real-time car positions.

# Python API
manager.race(2024, "monaco")
manager.race(2024, 8, port=8080)

# With force refresh from FastF1
manager.race(2024, "monaco", force_update=True)
# CLI
f1-replay race 2024 monaco
f1-replay race 2024 8 --port 8080

The viewer displays:

  • 2D track map with animated car positions
  • Driver colors and identification
  • Race progression from telemetry data

CLI Reference

# Race replay
f1-replay race <year> <round|name> [--port PORT]

# Browse seasons
f1-replay seasons [year]

# Standalone API server
f1-replay server [--port PORT]

# Configuration
f1-replay config                          # Show current config
f1-replay config --set-cache-dir /path    # Set cache directory

Configuration

from f1_replay import set_cache_dir, get_cache_dir

set_cache_dir("/path/to/data")    # Persists to ~/.f1replay/config.json
get_cache_dir()                   # Current cache directory
# Environment variable (highest priority)
export F1_REPLAY_CACHE_DIR=/path/to/data

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


Cache Structure

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

Requirements

  • Python 3.9+
  • FastF1
  • Flask
  • Polars
  • Matplotlib

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.8.tar.gz (99.2 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.8-py3-none-any.whl (112.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: f1_replay-0.1.8.tar.gz
  • Upload date:
  • Size: 99.2 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.8.tar.gz
Algorithm Hash digest
SHA256 1ab19094e02fd4790feb151030b80db8d8260406b38edc27d0b8b44ecfdc03df
MD5 f4eb9afd48267e8d913c50d8a279cee3
BLAKE2b-256 5118c7465eb9f9da57f08c5fc54e0f81ea5acb08f63703fb69b4c8304860d6df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: f1_replay-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 112.1 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 73fc5e0bcde112f4c2cbd37a91d2082d58b3193c59571070378028c9fd5f5cc1
MD5 f496b02e73a521234a43315618f49ec0
BLAKE2b-256 046ba1ee4cbd1f2c9d3e4f42b51c6747c2886d2dbabfdcdf5db84ff09a6d6559

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