A production-grade, asynchronous Python wrapper for the OpenF1 API.
- Fully Async β Built on
httpx.AsyncClientwith first-classasync/awaitsupport. - Sync Wrapper β
OpenF1Clientfor users who don't need async. - All 18 Endpoints β Complete coverage: telemetry, laps, drivers, sessions, weather, pit stops, stints, overtakes, race control, team radio, championship standings, results, starting grid, and more.
- Pydantic V2 Models β Every response is validated and returned as a strict, typed model.
- Auto-Retry β Exponential backoff on 429/5xx via
tenacity. - Rate Limiting β Built-in client-side throttle (3 req/s free tier).
- Response Caching β Optional in-memory TTL cache.
- CLI Tool β Query the API from your terminal.
- DataFrame Support β Optional
pandasintegration. - Production-Ready β Custom exceptions, structured logging, connection pooling.
pip install pyopenf1With pandas support:
pip install pyopenf1[pandas]import asyncio
from pyopenf1 import AsyncOpenF1Client
async def main() -> None:
async with AsyncOpenF1Client() as client:
# Fetch telemetry
car_data = await client.telemetry.get_car_data(driver_number=1, session_key=9159)
for entry in car_data[:5]:
print(f"Speed: {entry.speed} km/h | Gear: {entry.n_gear}")
# Fetch drivers
drivers = await client.drivers.get_drivers(session_key=9158)
for d in drivers[:3]:
print(f"#{d.driver_number} {d.full_name} - {d.team_name}")
asyncio.run(main())from pyopenf1 import OpenF1Client
with OpenF1Client() as client:
drivers = client.drivers.get_drivers(session_key=9158)
for d in drivers:
print(f"{d.name_acronym} - {d.team_name}")pyopenf1 car-data --driver 1 --session 9159 --format table
pyopenf1 drivers --session 9158 --format json
pyopenf1 weather --meeting 1208 --format csv --output weather.csvfrom pyopenf1.ext.pandas import to_dataframe
data = await client.telemetry.get_car_data(driver_number=1)
df = to_dataframe(data)
print(df.describe())async with AsyncOpenF1Client(
cache_ttl=300.0, # Cache responses for 5 minutes
max_retries=5, # Retry up to 5 times
max_per_second=6.0, # Sponsor-tier rate limit
max_per_minute=60.0,
) as client:
...| Namespace | Methods | OpenF1 Endpoints |
|---|---|---|
client.telemetry |
get_car_data(), get_location() |
/car_data, /location |
client.sessions |
get_sessions(), get_meetings() |
/sessions, /meetings |
client.drivers |
get_drivers() |
/drivers |
client.timing |
get_laps(), get_intervals(), get_positions() |
/laps, /intervals, /position |
client.race |
get_race_control(), get_pit_stops(), get_stints(), get_overtakes() |
/race_control, /pit, /stints, /overtakes |
client.championship |
get_drivers_championship(), get_teams_championship() |
/championship_drivers, /championship_teams |
client.results |
get_session_results(), get_starting_grid() |
/session_result, /starting_grid |
client.weather |
get_weather() |
/weather |
client.team_radio |
get_team_radio() |
/team_radio |
pyopenf1/
βββ __init__.py # Public API surface
βββ client.py # AsyncOpenF1Client facade
βββ sync_client.py # OpenF1Client (sync wrapper)
βββ cli.py # Click CLI
βββ exceptions.py # Custom exception hierarchy
βββ core/
β βββ http_client.py # httpx wrapper + retry + logging
β βββ rate_limiter.py # Token-bucket rate limiter
β βββ cache.py # In-memory TTL cache
βββ models/ # Pydantic V2 data models
β βββ telemetry.py # CarData, Location
β βββ session.py # Session, Meeting
β βββ driver.py # Driver
β βββ timing.py # Lap, Interval, Position
β βββ race.py # RaceControl, Pit, Stint, Overtake
β βββ championship.py # ChampionshipDriver, ChampionshipTeam
β βββ results.py # SessionResult, StartingGrid
β βββ weather.py # Weather
β βββ team_radio.py # TeamRadio
βββ endpoints/ # API endpoint classes
β βββ telemetry_api.py
β βββ session_api.py
β βββ driver_api.py
β βββ timing_api.py
β βββ race_api.py
β βββ championship_api.py
β βββ results_api.py
β βββ weather_api.py
β βββ team_radio_api.py
βββ ext/
βββ pandas.py # Optional DataFrame integration
# Install dev dependencies
poetry install
# Lint & format
poetry run ruff check .
poetry run ruff format .
# Type check
poetry run mypy pyopenf1/
# Test
poetry run pytest -v
# Build docs
poetry run mkdocs serveDistributed under the MIT License. See LICENSE for details.