Open F1 Python API Docs | dltHub

Build a Open F1-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.

Last updated:

OpenF1 is an open-source REST API providing real-time and historical Formula 1 data (timing, telemetry, session info) in JSON and CSV formats. The REST API base URL is https://api.openf1.org and OAuth2 access token (Bearer) for authenticated/real-time endpoints; historical data often accessible without auth..

dlt is an open-source Python library that handles authentication, pagination, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv pip install "dlt[workspace]" and start loading Open F1 data in under 10 minutes.


What data can I load from Open F1?

Here are some of the endpoints you can load from Open F1:

ResourceEndpointMethodData selectorDescription
sessions/v1/sessionsGET(top-level array)Session metadata (meeting_key, session_key, date_start, session_name, etc.)
drivers/v1/driversGET(top-level array)Driver details for a session (driver_number, name, team, etc.)
laps/v1/lapsGET(top-level array)Detailed lap records (lap_number, driver_number, lap_time, etc.)
location/v1/locationGET(top-level array)Per-sample location telemetry (date, x,y,z,driver_number,session_key)
car_data/v1/car_dataGET(top-level array)Car telemetry samples (speed, rpm, gears, etc.)
position/v1/positionGET(top-level array)Position changes and placements throughout a session
pit/v1/pitGET(top-level array)Pit stops (stop_duration, driver_number, session_key)
session_result/v1/session_resultGET(top-level array)Session standings / results
race_control/v1/race_controlGET(top-level array)Race control messages and flags
overtakes/v1/overtakesGET(top-level array)Overtake events
team_radio/v1/team_radioGET(top-level array)Team radio messages

How do I authenticate with the Open F1 API?

Obtain an OAuth2 access token by POSTing username and password to https://api.openf1.org/token; include the returned access_token in requests using the Authorization: Bearer header. Tokens expire after 3600 seconds.

1. Get your credentials

  1. Sponsor or create an account per openf1.org (paid sponsorship for live access). 2) Use your account credentials (username/password) to POST to https://api.openf1.org/token with Content-Type: application/x-www-form-urlencoded. 3) On success, store access_token and expires_in (seconds). 4) Refresh by re-requesting a token when expired.

2. Add them to .dlt/secrets.toml

[sources.formula_one_source] api_username = "YOUR_USERNAME" api_password = "YOUR_PASSWORD"

dlt reads this automatically at runtime — never hardcode tokens in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.


How do I set up and run the pipeline?

Set up a virtual environment and install dlt:

uv venv && source .venv/bin/activate uv pip install "dlt[workspace]"

1. Install the dlt AI Workbench:

dlt ai init --agent <your-agent> # <agent>: claude | cursor | codex

This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →

2. Install the rest-api-pipeline toolkit:

dlt ai toolkit rest-api-pipeline install

This loads the skills and context about dlt the agent uses to build the pipeline iteratively, efficiently, and safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →

3. Start LLM-assisted coding:

Use /find-source to load data from the Open F1 API into DuckDB.

The rest-api-pipeline toolkit takes over from here — it reads relevant API documentation, presents you with options for which endpoints to load, and follows a structured workflow to scaffold, debug, and validate the pipeline step by step.

4. Run the pipeline:

python formula_one_pipeline.py

If everything is configured correctly, you'll see output like this:

Pipeline formula_one_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset formula_one_data The duckdb destination used duckdb:/formula_one.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs

Inspect your pipeline and data:

dlt pipeline formula_one_pipeline show

This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.


Python pipeline example

This example loads laps and sessions from the Open F1 API into DuckDB. It mirrors the endpoint and data selector configuration from the table above:

import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def formula_one_source(api_username, api_password=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://api.openf1.org", "auth": { "type": "oauth2_password (use dlt's 'bearer' for requests after token exchange)", "access_token": api_username, api_password, }, }, "resources": [ {"name": "laps", "endpoint": {"path": "v1/laps"}}, {"name": "sessions", "endpoint": {"path": "v1/sessions"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="formula_one_pipeline", destination="duckdb", dataset_name="formula_one_data", ) load_info = pipeline.run(formula_one_source()) print(load_info)

To add more endpoints, append entries from the resource table to the "resources" list using the same name, path, and data_selector pattern.


How do I query the loaded data?

Once the pipeline runs, dlt creates one table per resource. You can query with Python or SQL.

Python (pandas DataFrame):

import dlt data = dlt.pipeline("formula_one_pipeline").dataset() sessions_df = data.laps.df() print(sessions_df.head())

SQL (DuckDB example):

SELECT * FROM formula_one_data.laps LIMIT 10;

In a marimo or Jupyter notebook:

import dlt data = dlt.pipeline("formula_one_pipeline").dataset() data.laps.df().head()

See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.


What destinations can I load Open F1 data to?

dlt supports loading into any of these destinations — only the destination parameter changes:

DestinationExample value
DuckDB (local, default)"duckdb"
PostgreSQL"postgres"
BigQuery"bigquery"
Snowflake"snowflake"
Redshift"redshift"
Databricks"databricks"
Filesystem (S3, GCS, Azure)"filesystem"

Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.


Troubleshooting

Authentication failures

If POST to /token returns 4xx, verify username/password and sponsorship status. Tokens expire in 3600s; include Authorization: Bearer <access_token> for protected endpoints.

Rate limits & access tiers

Historical endpoints are generally available without auth; real-time/live data requires authenticated subscription and has higher rate limits. If rate-limited, the API will return HTTP 429 — implement exponential backoff and prefer MQTT/Websocket for live streaming.

Data format & selectors

Most GET endpoints return a top-level JSON array of records (no wrapper key). If you receive an object instead, inspect the response — sample telemetry endpoints (MQTT/Websocket) include additional _id and _key fields.

Ensure that the API key is valid to avoid 401 Unauthorized errors. Also, verify endpoint paths and parameters to avoid 404 Not Found errors.


Next steps

Continue your data engineering journey with the other toolkits of the dltHub AI Workbench:

  • data-exploration — Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.
  • dlthub-runtime — Deploy, schedule, and monitor your pipeline in production.
dlt ai toolkit data-exploration install dlt ai toolkit dlthub-runtime install

Was this page helpful?

Community Hub

Need more dlt context for Open F1?

Request dlt skills, commands, AGENT.md files, and AI-native context.