A production-grade, asynchronous Python API wrapper for the OpenF1 API.
Project description
๐๏ธ pyopenf1
A production-grade, asynchronous Python wrapper for the OpenF1 API.
โจ Features
- 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.
๐ฆ Installation
pip install pyopenf1
With pandas support:
pip install pyopenf1[pandas]
๐ Quickstart
Async (recommended)
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())
Sync
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}")
CLI
pyopenf1 car-data --driver 1 --session 9159 --format table
pyopenf1 drivers --session 9158 --format json
pyopenf1 weather --meeting 1208 --format csv --output weather.csv
DataFrame
from pyopenf1.ext.pandas import to_dataframe
data = await client.telemetry.get_car_data(driver_number=1)
df = to_dataframe(data)
print(df.describe())
โ๏ธ Configuration
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:
...
๐ก Available Endpoints
| 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 |
๐๏ธ Architecture
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
๐งช Development
# 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 serve
๐ License
Distributed under the MIT License. See LICENSE for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyopenf1-0.1.0.tar.gz.
File metadata
- Download URL: pyopenf1-0.1.0.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
080eca5c321b7428fa68b96635e565b096838692317192e5ee6828f5e74097ab
|
|
| MD5 |
9d84d35ff4406e83536c02ad2edfc155
|
|
| BLAKE2b-256 |
54a627da5428755f745d7b7c2f2d18ac8a81ccea1af992393f3462efb8b2128f
|
Provenance
The following attestation bundles were made for pyopenf1-0.1.0.tar.gz:
Publisher:
publish.yml on DivyamSamarwal/pyopenf1
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyopenf1-0.1.0.tar.gz -
Subject digest:
080eca5c321b7428fa68b96635e565b096838692317192e5ee6828f5e74097ab - Sigstore transparency entry: 1393587241
- Sigstore integration time:
-
Permalink:
DivyamSamarwal/pyopenf1@e79c5886b183bc5af4648ff9fa76466ec288b343 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/DivyamSamarwal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e79c5886b183bc5af4648ff9fa76466ec288b343 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyopenf1-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyopenf1-0.1.0-py3-none-any.whl
- Upload date:
- Size: 33.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a01c957eab9e4c08cab95b9ffff593e713a2ad071a2e784663abe911d3a73ac1
|
|
| MD5 |
d1da50f61d6b6e6655d77b96fa99f19f
|
|
| BLAKE2b-256 |
2347e88aa10911da6509d1e4c2bdec408bc8567d8be8af90298302ff015eae7b
|
Provenance
The following attestation bundles were made for pyopenf1-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on DivyamSamarwal/pyopenf1
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyopenf1-0.1.0-py3-none-any.whl -
Subject digest:
a01c957eab9e4c08cab95b9ffff593e713a2ad071a2e784663abe911d3a73ac1 - Sigstore transparency entry: 1393587269
- Sigstore integration time:
-
Permalink:
DivyamSamarwal/pyopenf1@e79c5886b183bc5af4648ff9fa76466ec288b343 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/DivyamSamarwal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e79c5886b183bc5af4648ff9fa76466ec288b343 -
Trigger Event:
push
-
Statement type: