### Fetch Starting Grid with JavaScript Source: https://openf1.org/docs Use the Fetch API in JavaScript to get starting grid data from the OpenF1 API and log the JSON content to the console. ```javascript fetch("https://api.openf1.org/v1/starting_grid?session_key=7783&position%3C=3") .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Get Starting Grid Source: https://openf1.org/docs Fetches the starting grid for a specific Formula 1 session. You can filter results by position. ```APIDOC ## GET /v1/starting_grid ### Description Provides the starting grid for the upcoming race. This data becomes available a few minutes after the official results are published on the official Formula 1 website. ### Method GET ### Endpoint /v1/starting_grid ### Query Parameters - **session_key** (integer) - Required - The unique identifier for the session. Use `latest` to identify the latest or current session. - **position** (integer) - Optional - Filters results to include only drivers at or before the specified position. ### Request Example ``` https://api.openf1.org/v1/starting_grid?session_key=7783&position<=3 ``` ### Response #### Success Response (200) - **position** (integer) - Position on the grid. - **driver_number** (integer) - The unique number assigned to an F1 driver for the season. - **lap_duration** (float) - Duration, in seconds, of the qualifying lap. - **meeting_key** (integer) - The unique identifier for the meeting. Use `latest` to identify the latest or current meeting. - **session_key** (integer) - The unique identifier for the session. Use `latest` to identify the latest or current session. ### Response Example ```json [ { "position": 1, "driver_number": 1, "lap_duration": 76.732, "meeting_key": 1143, "session_key": 7783 } ] ``` ``` -------------------------------- ### Fetch Starting Grid with cURL Source: https://openf1.org/docs Use cURL to make a GET request to the OpenF1 API for starting grid data. Filter results by session key and position. ```bash curl "https://api.openf1.org/v1/starting_grid?session_key=7783&position%3C=3" ``` -------------------------------- ### Fetch Starting Grid with Python Source: https://openf1.org/docs Retrieve starting grid data using Python's `urllib.request` and `json` libraries. The data can optionally be loaded into a pandas DataFrame. ```python from urllib.request import urlopen import json response = urlopen("https://api.openf1.org/v1/starting_grid?session_key=7783&position%3C=3") data = json.loads(response.read().decode('utf-8')) print(data) # If you want, you can import the results in a DataFrame (you need to install the `pandas` package first) # import pandas as pd # df = pd.DataFrame(data) ``` -------------------------------- ### Fetch Starting Grid with R Source: https://openf1.org/docs Access starting grid information using R with the `httr` and `jsonlite` packages. The fetched data can be converted into a data frame. ```r # If needed, install libraries # install.packages('httr') # install.packages('jsonlite') library(httr) library(jsonlite) response <- GET("https://api.openf1.org/v1/starting_grid?session_key=7783&position%3C=3") parsed_data <- fromJSON(content(response, 'text')) print(parsed_data) # If you want, you can import the results in a DataFrame # df <- do.call(rbind, lapply(parsed_data, data.frame, stringsAsFactors = FALSE)) # df <- as.data.frame(t(as.matrix(df))) ``` -------------------------------- ### Fetch Weather Data with R Source: https://openf1.org/docs Use R with the `httr` and `jsonlite` packages to retrieve and parse weather data. This example shows how to make the GET request and convert the response to a data frame. ```r # If needed, install libraries # install.packages('httr') # install.packages('jsonlite') library(httr) library(jsonlite) response <- GET('https://api.openf1.org/v1/weather?meeting_key=1208&wind_direction>=130&track_temperature>=52') parsed_data <- fromJSON(content(response, 'text')) print(parsed_data) # If you want, you can import the results in a DataFrame # df <- do.call(rbind, lapply(parsed_data, data.frame, stringsAsFactors = FALSE)) # df <- as.data.frame(t(as.matrix(df))) ``` -------------------------------- ### Fetch Weather Data with cURL Source: https://openf1.org/docs Use cURL to make a GET request to the OpenF1 weather API. This example retrieves weather data for a specific meeting, filtering by wind direction and track temperature. ```shell curl "https://api.openf1.org/v1/weather?meeting_key=1208&wind_direction>=130&track_temperature>=52" ``` -------------------------------- ### Fetch Stints Data with cURL Source: https://openf1.org/docs Use this cURL command to make a GET request to the OpenF1 API for stint data, filtering by session key and tyre age at start. ```bash curl "https://api.openf1.org/v1/stints?session_key=9165&tyre_age_at_start>=3" ``` -------------------------------- ### Fetch Team Radio Data (R) Source: https://openf1.org/docs Access team radio data using R with the `httr` and `jsonlite` packages. This example demonstrates making a GET request and parsing the JSON content. DataFrame conversion is provided as a commented-out option. ```r # If needed, install libraries # install.packages('httr') # install.packages('jsonlite') library(httr) library(jsonlite) response <- GET('https://api.openf1.org/v1/team_radio?session_key=9158&driver_number=11') parsed_data <- fromJSON(content(response, 'text')) print(parsed_data) # If you want, you can import the results in a DataFrame # df <- do.call(rbind, lapply(parsed_data, data.frame, stringsAsFactors = FALSE)) # df <- as.data.frame(t(as.matrix(df))) ``` -------------------------------- ### Fetch Position Data with JavaScript Source: https://openf1.org/docs Use the Fetch API in JavaScript to get driver position data from the OpenF1 API and log the JSON content to the console. ```javascript fetch( "https://api.openf1.org/v1/position?meeting_key=1217&driver_number=40&position<=3", ) .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Get Stints Information Source: https://openf1.org/docs Retrieves a list of stints for a given session, with an option to filter by tyre age at the start of the stint. ```APIDOC ## GET /v1/stints ### Description Provides information about individual stints. A stint refers to a period of continuous driving by a driver during a session. ### Method GET ### Endpoint /v1/stints ### Parameters #### Query Parameters - **session_key** (integer) - Required - The unique identifier for the session. - **tyre_age_at_start** (integer) - Optional - Filters stints based on the age of the tyres in laps completed at the start of the stint. ### Response #### Success Response (200) - **compound** (string) - The specific compound of tyre used during the stint (`SOFT`, `MEDIUM`, `HARD`, ...). - **driver_number** (integer) - The unique number assigned to an F1 driver for the season. - **lap_end** (integer) - Number of the last completed lap in this stint. - **lap_start** (integer) - Number of the initial lap in this stint (starts at 1). - **meeting_key** (integer) - The unique identifier for the meeting. - **session_key** (integer) - The unique identifier for the session. - **stint_number** (integer) - The sequential number of the stint within the session (starts at 1). - **tyre_age_at_start** (integer) - The age of the tyres at the start of the stint, in laps completed. ### Request Example ```bash curl "https://api.openf1.org/v1/stints?session_key=9165&tyre_age_at_start>=3" ``` ### Response Example ```json [ { "compound": "SOFT", "driver_number": 16, "lap_end": 20, "lap_start": 1, "meeting_key": 1219, "session_key": 9165, "stint_number": 1, "tyre_age_at_start": 3 }, { "compound": "SOFT", "driver_number": 20, "lap_end": 62, "lap_start": 44, "meeting_key": 1219, "session_key": 9165, "stint_number": 3, "tyre_age_at_start": 3 } ] ``` ``` -------------------------------- ### Retrieve Driver Information (cURL) Source: https://openf1.org/docs Use cURL to make a GET request to the OpenF1 API to fetch driver details for a specific driver number and session key. ```bash curl "https://api.openf1.org/v1/drivers?driver_number=1&session_key=9158" ``` -------------------------------- ### Fetch Position Data with cURL Source: https://openf1.org/docs Use cURL to make a GET request to the OpenF1 API for driver position data. Specify meeting key, driver number, and position constraints. ```bash curl "https://api.openf1.org/v1/position?meeting_key=1217&driver_number=40&position<=3" ``` -------------------------------- ### Get Weather Data Source: https://openf1.org/docs Retrieves current weather conditions for a specified meeting, with optional filters for wind direction and track temperature. ```APIDOC ## GET /weather ### Description Retrieves current weather conditions for a specified meeting, with optional filters for wind direction and track temperature. ### Method GET ### Endpoint https://api.openf1.org/v1/weather ### Parameters #### Query Parameters - **meeting_key** (integer) - Required - The unique identifier for the meeting. Use `latest` to identify the latest or current meeting. - **wind_direction** (integer) - Optional - Filters results for wind direction greater than or equal to the specified value (0-359). - **track_temperature** (float) - Optional - Filters results for track temperature greater than or equal to the specified value (°C). ### Request Example ```json { "example": "https://api.openf1.org/v1/weather?meeting_key=1208&wind_direction>=130&track_temperature>=52" } ``` ### Response #### Success Response (200) - **air_temperature** (float) - Air temperature (°C). - **date** (string) - The UTC date and time, in ISO 8601 format. - **humidity** (integer) - Relative humidity (%). - **meeting_key** (integer) - The unique identifier for the meeting. - **pressure** (float) - Air pressure (mbar). - **rainfall** (integer) - Whether there is rainfall. - **session_key** (integer) - The unique identifier for the session. - **track_temperature** (float) - Track temperature (°C). - **wind_direction** (integer) - Wind direction (°), from 0° to 359°. - **wind_speed** (float) - Wind speed (m/s). #### Response Example ```json [ { "air_temperature": 27.8, "date": "2023-05-07T18:42:25.233000+00:00", "humidity": 58, "meeting_key": 1208, "pressure": 1018.7, "rainfall": 0, "session_key": 9078, "track_temperature": 52.5, "wind_direction": 136, "wind_speed": 2.4 } ] ``` ``` -------------------------------- ### Fetch Car Data with R Source: https://openf1.org/docs This R script uses the `httr` and `jsonlite` packages to fetch and parse car data. It shows how to make a GET request and convert the JSON response. DataFrame conversion is also outlined. ```r # If needed, install libraries # install.packages('httr') # install.packages('jsonlite') library(httr) library(jsonlite) response <- GET('https://api.openf1.org/v1/car_data?driver_number=55&session_key=9159&speed>=315') parsed_data <- fromJSON(content(response, 'text')) print(parsed_data) # If you want, you can import the results in a DataFrame # df <- do.call(rbind, lapply(parsed_data, data.frame, stringsAsFactors = FALSE)) # df <- as.data.frame(t(as.matrix(df))) ``` -------------------------------- ### Get Sessions Source: https://openf1.org/docs Fetches session data based on country name, session name, and year. This is useful for retrieving details about past or future F1 events. ```APIDOC ## GET /sessions ### Description Retrieves information about Formula 1 sessions, including practice, qualifying, and race events. Sessions are updated daily at midnight UTC. ### Method GET ### Endpoint /v1/sessions ### Parameters #### Query Parameters - **country_name** (string) - Required - The name of the country where the Grand Prix is held (e.g., "Belgium"). - **session_name** (string) - Required - The name of the session (e.g., "Sprint Qualifying", "Race"). - **year** (integer) - Required - The year the session took place or will take place. ### Request Example ```bash curl "https://api.openf1.org/v1/sessions?country_name=Belgium&session_name=Sprint%20Qualifying&year=2023" ``` ### Response #### Success Response (200) - **circuit_key** (integer) - The unique identifier for the circuit. - **circuit_short_name** (string) - The short name of the circuit. - **country_code** (string) - A code that uniquely identifies the country. - **country_key** (integer) - The unique identifier for the country. - **country_name** (string) - The full name of the country. - **date_end** (string) - The UTC ending date and time in ISO 8601 format. - **date_start** (string) - The UTC starting date and time in ISO 8601 format. - **gmt_offset** (string) - The difference between local time and GMT. - **is_cancelled** (boolean) - Indicates if the session was cancelled. - **location** (string) - The city or geographical location of the event. - **meeting_key** (integer) - The unique identifier for the meeting. - **session_key** (integer) - The unique identifier for the session. - **session_name** (string) - The name of the session. - **session_type** (string) - The type of the session. - **year** (integer) - The year the event takes place. #### Response Example ```json [ { "circuit_key": 7, "circuit_short_name": "Spa-Francorchamps", "country_code": "BEL", "country_key": 16, "country_name": "Belgium", "date_end": "2023-07-29T15:35:00+00:00", "date_start": "2023-07-29T15:05:00+00:00", "gmt_offset": "02:00:00", "is_cancelled": false, "location": "Spa-Francorchamps", "meeting_key": 1216, "session_key": 9140, "session_name": "Sprint Qualifying", "session_type": "Sprint Qualifying", "year": 2023 } ] ``` ``` -------------------------------- ### Fetch Session Results with cURL Source: https://openf1.org/docs Use cURL to make a GET request to the session_result endpoint. Filter results by session key and position. ```bash curl "https://api.openf1.org/v1/session_result?session_key=7782&position%3C=3" ``` -------------------------------- ### Fetch Pit Data with JavaScript Source: https://openf1.org/docs Use the Fetch API in JavaScript to get pit lane data from the OpenF1 API. The response is converted to JSON and logged to the console. This is suitable for web-based applications. ```javascript fetch("https://api.openf1.org/v1/pit?session_key=9877&stop_duration<2.3") .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Fetch Pit Data with cURL Source: https://openf1.org/docs Use cURL to make a GET request to the OpenF1 API for pit lane data, filtering by session key and stop duration. This is a simple way to test API endpoints. ```bash curl "https://api.openf1.org/v1/pit?session_key=9877&stop_duration<2.3" ``` -------------------------------- ### Fetch Stints Data with JavaScript Source: https://openf1.org/docs This JavaScript snippet demonstrates how to fetch stint data from the OpenF1 API using the `fetch` API and log the JSON content to the console. ```javascript fetch("https://api.openf1.org/v1/stints?session_key=9165&tyre_age_at_start>=3") .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Fetch Session Data with R Source: https://openf1.org/docs This R script demonstrates how to fetch session data from the OpenF1 API using the `httr` and `jsonlite` packages. It prints the parsed JSON data and includes commented-out code for converting the results into a data frame. ```r # If needed, install libraries # install.packages('httr') # install.packages('jsonlite') library(httr) library(jsonlite) response <- GET('https://api.openf1.org/v1/sessions?country_name=Belgium&session_name=Sprint%20Qualifying&year=2023') parsed_data <- fromJSON(content(response, 'text')) print(parsed_data) # If you want, you can import the results in a DataFrame # df <- do.call(rbind, lapply(parsed_data, data.frame, stringsAsFactors = FALSE)) # df <- as.data.frame(t(as.matrix(df))) ``` -------------------------------- ### Fetch Lap Data with JavaScript Source: https://openf1.org/docs This JavaScript snippet demonstrates how to fetch lap data from the OpenF1 API using the `fetch` API and log the JSON content to the console. ```javascript fetch( "https://api.openf1.org/v1/laps?session_key=9161&driver_number=63&lap_number=8", ) .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Get Pit Information Source: https://openf1.org/docs Retrieves pit lane data for a given session, with optional filtering. ```APIDOC ## GET /v1/pit ### Description Provides information about cars going through the pit lane. ### Method GET ### Endpoint /v1/pit ### Query Parameters - **session_key** (integer) - Required - The unique identifier for the session. - **stop_duration** (float) - Optional - Filters results for pit stops with a duration less than the specified value (e.g., `stop_duration<2.3`). This field is only available from the 2024 US GP onwards. ### Response #### Success Response (200) - **date** (string) - The UTC date and time, in ISO 8601 format. - **driver_number** (integer) - The unique number assigned to an F1 driver for the season. - **lane_duration** (float) - The time spent in the pit lane, in seconds. - **lap_number** (integer) - The sequential number of the lap within the session (starts at 1). - **meeting_key** (integer) - The unique identifier for the meeting. - **pit_duration** (float) - Same as 'lane_duration'. This field will be removed at the end of the 2026 season. - **session_key** (integer) - The unique identifier for the session. - **stop_duration** (float) - The stationary pit stop time, in seconds. ### Request Example ``` https://api.openf1.org/v1/pit?session_key=9877&stop_duration<2.3 ``` ### Response Example ```json [ { "date": "2025-10-26T20:46:37.358000+00:00", "driver_number": 16, "lane_duration": 22.215, "lap_number": 31, "meeting_key": 1272, "pit_duration": 22.215, "session_key": 9877, "stop_duration": 2.2 } ] ``` ``` -------------------------------- ### Retrieve Driver Information (R) Source: https://openf1.org/docs Use R with the `httr` and `jsonlite` packages to retrieve and parse driver data from the OpenF1 API. The data can be converted into a DataFrame. ```r # If needed, install libraries # install.packages('httr') # install.packages('jsonlite') library(httr) library(jsonlite) response <- GET('https://api.openf1.org/v1/drivers?driver_number=1&session_key=9158') parsed_data <- fromJSON(content(response, 'text')) print(parsed_data) # If you want, you can import the results in a DataFrame # df <- do.call(rbind, lapply(parsed_data, data.frame, stringsAsFactors = FALSE)) # df <- as.data.frame(t(as.matrix(df))) ``` -------------------------------- ### Get Overtakes Source: https://openf1.org/docs Retrieves overtake data for a specific session, filtering by overtaking driver, overtaken driver, and position. ```APIDOC ## GET /v1/overtakes ### Description Provides information about overtakes. An overtake refers to one driver (the overtaking driver) exchanging positions with another driver (the overtaken driver). This includes both on-track passes and position changes resulting from pit stops or post-race penalties. This data is only available during races and may be incomplete. ### Endpoint https://api.openf1.org/v1/overtakes ### Query Parameters - **session_key** (integer) - Required - The unique identifier for the session. Use `latest` to identify the latest or current session. - **overtaking_driver_number** (integer) - Optional - The unique number assigned to the overtaking F1 driver. - **overtaken_driver_number** (integer) - Optional - The unique number assigned to the overtaken F1 driver. - **position** (integer) - Optional - The position of the overtaking F1 driver after the overtake was completed (starts at 1). ### Response #### Success Response (200) - **date** (string) - The UTC date and time, in ISO 8601 format. - **meeting_key** (integer) - The unique identifier for the meeting. - **overtaken_driver_number** (integer) - The unique number assigned to the overtaken F1 driver. - **overtaking_driver_number** (integer) - The unique number assigned to the overtaking F1 driver. - **position** (integer) - The position of the overtaking F1 driver after the overtake was completed. - **session_key** (integer) - The unique identifier for the session. ### Response Example ```json [ { "date": "2024-11-03T15:50:07.565000+00:00", "meeting_key": 1249, "overtaken_driver_number": 4, "overtaking_driver_number": 63, "position": 1, "session_key": 9636 } ] ``` ``` -------------------------------- ### Get Driver Positions Source: https://openf1.org/docs Fetches driver position data for a specific meeting, with optional filters for driver number and position. ```APIDOC ## GET /position ### Description Provides driver positions throughout a session, including initial placement and subsequent changes. ### Method GET ### Endpoint https://api.openf1.org/v1/position ### Parameters #### Query Parameters - **meeting_key** (integer) - Required - The unique identifier for the meeting. Use `latest` to identify the latest or current meeting. - **driver_number** (integer) - Optional - The unique number assigned to an F1 driver for the season. - **position** (integer) - Optional - Position of the driver (starts at 1). Can be used with comparison operators like `<=`, `<`, `>=`, `>`. ### Response #### Success Response (200) - **date** (string) - The UTC date and time, in ISO 8601 format. - **driver_number** (integer) - The unique number assigned to an F1 driver for the season. - **meeting_key** (integer) - The unique identifier for the meeting. - **position** (integer) - Position of the driver (starts at 1). - **session_key** (integer) - The unique identifier for the session. ### Response Example ```json [ { "date": "2023-08-26T09:30:47.199000+00:00", "driver_number": 40, "meeting_key": 1217, "position": 2, "session_key": 9144 }, { "date": "2023-08-26T09:35:51.477000+00:00", "driver_number": 40, "meeting_key": 1217, "position": 3, "session_key": 9144 } ] ``` ``` -------------------------------- ### Get Drivers Information Source: https://openf1.org/docs This endpoint retrieves detailed information about drivers participating in a specific session. You can filter by `driver_number` and `session_key`. ```APIDOC ## GET /v1/drivers ### Description Retrieve detailed information about the drivers participating in a specific session. ### Method GET ### Endpoint /v1/drivers ### Parameters #### Query Parameters - **driver_number** (integer) - Required - The unique number assigned to an F1 driver for the season. - **session_key** (integer) - Required - The unique identifier for the session. ### Response #### Success Response (200) - **broadcast_name** (string) - The driver's name, as displayed on TV. - **driver_number** (integer) - The unique number assigned to an F1 driver for the season. - **first_name** (string) - The driver's first name. - **full_name** (string) - The driver's full name. - **headshot_url** (string) - URL of the driver's face photo. - **last_name** (string) - The driver's last name. - **meeting_key** (integer) - The unique identifier for the meeting. - **name_acronym** (string) - Three-letter acronym of the driver's name. - **session_key** (integer) - The unique identifier for the session. - **team_colour** (string) - The hexadecimal color value (RRGGBB) of the driver's team. - **team_name** (string) - Name of the driver's team. ### Request Example ```json { "example": "request body" } ``` ### Response Example ```json [ { "broadcast_name": "M VERSTAPPEN", "driver_number": 1, "first_name": "Max", "full_name": "Max VERSTAPPEN", "headshot_url": "https://www.formula1.com/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01.png.transform/1col/image.png", "last_name": "Verstappen", "meeting_key": 1219, "name_acronym": "VER", "session_key": 9158, "team_colour": "3671C6", "team_name": "Red Bull Racing" } ] ``` ``` -------------------------------- ### Fetch Stints Data with Python Source: https://openf1.org/docs This Python script fetches stint data from the OpenF1 API using the `urllib.request` and `json` libraries. It prints the decoded JSON response. Uncomment the pandas lines to load the data into a DataFrame. ```python from urllib.request import urlopen import json response = urlopen('https://api.openf1.org/v1/stints?session_key=9165&tyre_age_at_start>=3') data = json.loads(response.read().decode('utf-8')) print(data) # If you want, you can import the results in a DataFrame (you need to install the `pandas` package first) # import pandas as pd # df = pd.DataFrame(data) ``` -------------------------------- ### Get Team Radio Communications Source: https://openf1.org/docs Retrieves team radio communications for a specific session and driver. Only a limited selection of communications are included. ```APIDOC ## GET /v1/team_radio ### Description Retrieves team radio communications for a specific session and driver. This endpoint provides a curated selection of radio exchanges, not the complete record. ### Method GET ### Endpoint /v1/team_radio ### Parameters #### Query Parameters - **session_key** (integer) - Required - The unique identifier for the session. Use `latest` to identify the latest or current session. - **driver_number** (integer) - Required - The unique number assigned to an F1 driver for the season. ### Response #### Success Response (200) - **date** (string) - The UTC date and time, in ISO 8601 format. - **driver_number** (integer) - The unique number assigned to an F1 driver for the season. - **meeting_key** (integer) - The unique identifier for the meeting. - **recording_url** (string) - URL of the radio recording. - **session_key** (integer) - The unique identifier for the session. ### Request Example ```json { "example": "https://api.openf1.org/v1/team_radio?session_key=9158&driver_number=11" } ``` ### Response Example ```json [ { "date": "2023-09-15T09:40:43.005000+00:00", "driver_number": 11, "meeting_key": 1219, "recording_url": "https://livetiming.formula1.com/static/2023/2023-09-17_Singapore_Grand_Prix/2023-09-15_Practice_1/TeamRadio/SERPER01_11_20230915_104008.mp3", "session_key": 9158 } ] ``` ``` -------------------------------- ### Fetch Session Results with JavaScript Source: https://openf1.org/docs Use the Fetch API in JavaScript to retrieve session results from the OpenF1 API and log the JSON content to the console. ```javascript fetch("https://api.openf1.org/v1/session_result?session_key=7782&position%3C=3") .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Get Session Results Source: https://openf1.org/docs Fetches the results for a given session, optionally filtered by position. This endpoint is useful for retrieving standings after a race or qualifying. ```APIDOC ## GET /v1/session_result ### Description Provides standings after a session. This data becomes available a few minutes after the official results are published on the official Formula 1 website. ### Method GET ### Endpoint https://api.openf1.org/v1/session_result ### Parameters #### Query Parameters - **session_key** (integer) - Required - The unique identifier for the session. Use `latest` to identify the latest or current session. - **position** (integer) - Optional - Filters results to include only drivers at or below the specified position. ### Request Example ```bash curl "https://api.openf1.org/v1/session_result?session_key=7782&position%3C=3" ``` ### Response #### Success Response (200) - **dnf** (boolean) - Indicates whether the driver Did Not Finish the race. - **dns** (boolean) - Indicates whether the driver Did Not Start the race. - **dsq** (boolean) - Indicates whether the driver was disqualified. - **driver_number** (integer) - The unique number assigned to an F1 driver for the season. - **duration** (float) - Either the best lap time or the total race time, in seconds. - **gap_to_leader** (float) - The time gap to the session leader in seconds. - **number_of_laps** (integer) - Total number of laps completed during the session. - **meeting_key** (integer) - The unique identifier for the meeting. - **position** (integer) - The driver’s final position at the end of the session. - **session_key** (integer) - The unique identifier for the session. #### Response Example ```json [ { "dnf": false, "dns": false, "dsq": false, "driver_number": 1, "duration": 77.565, "gap_to_leader": 0, "number_of_laps": 24, "meeting_key": 1143, "position": 1, "session_key": 7782 } ] ``` ``` -------------------------------- ### Fetch Session Data with JavaScript Source: https://openf1.org/docs This JavaScript snippet uses the `fetch` API to retrieve session data from the OpenF1 API and logs the JSON content to the console. ```javascript fetch( "https://api.openf1.org/v1/sessions?country_name=Belgium&session_name=Sprint%20Qualifying&year=2023", ) .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Fetch Meetings Data with JavaScript Source: https://openf1.org/docs This JavaScript snippet demonstrates how to fetch meeting data from the API using the `fetch` API and log the JSON content to the console. ```javascript fetch("https://api.openf1.org/v1/meetings?year=2026&country_name=Singapore") .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Fetch Drivers Championship Standings (Python) Source: https://openf1.org/docs Retrieve championship standings using Python's urllib.request. Install pandas to load results into a DataFrame. ```python from urllib.request import urlopen import json response = urlopen('https://api.openf1.org/v1/championship_drivers?session_key=9839&driver_number=4&driver_number=81') data = json.loads(response.read().decode('utf-8')) print(data) # If you want, you can import the results in a DataFrame (you need to install the `pandas` package first) # import pandas as pd # df = pd.DataFrame(data) ``` -------------------------------- ### Fetch Weather Data with JavaScript Source: https://openf1.org/docs Use the Fetch API in JavaScript to asynchronously retrieve weather data from the OpenF1 API and log the JSON content to the console. ```javascript fetch( "https://api.openf1.org/v1/weather?meeting_key=1208&wind_direction>=130&track_temperature>=52", ) .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Get Intervals Source: https://openf1.org/docs Fetches real-time interval data between drivers and their gap to the race leader. This endpoint is available during races only and updates approximately every 4 seconds. ```APIDOC ## GET /intervals ### Description Fetches real-time interval data between drivers and their gap to the race leader. Available during races only, with updates approximately every 4 seconds. ### Method GET ### Endpoint https://api.openf1.org/v1/intervals ### Parameters #### Query Parameters - **session_key** (integer) - Required - The unique identifier for the session. Use `latest` to identify the latest or current session. - **interval** (float) - Required - The time gap to the car ahead in seconds. Can be used with comparison operators (e.g., `>0`, `<0.005`). ### Request Example ``` https://api.openf1.org/v1/intervals?session_key=9165&interval>0&interval<0.005 ``` ### Response #### Success Response (200) - **date** (string) - The UTC date and time, in ISO 8601 format. - **driver_number** (integer) - The unique number assigned to an F1 driver for the season. - **gap_to_leader** (float) - The time gap to the race leader in seconds, `+1 LAP` if lapped, or `null` for the race leader. - **interval** (float) - The time gap to the car ahead in seconds, `+1 LAP` if lapped, or `null` for the race leader. - **meeting_key** (integer) - The unique identifier for the meeting. - **session_key** (integer) - The unique identifier for the session. #### Response Example ```json [ { "date": "2023-09-17T13:31:02.395000+00:00", "driver_number": 1, "gap_to_leader": 41.019, "interval": 0.003, "meeting_key": 1219, "session_key": 9165 } ] ``` ``` -------------------------------- ### Fetch Lap Data with R Source: https://openf1.org/docs This R script shows how to retrieve and parse lap data from the OpenF1 API using the `httr` and `jsonlite` packages. The fetched data can be converted into a data frame. ```r # If needed, install libraries # install.packages('httr') # install.packages('jsonlite') library(httr) library(jsonlite) response <- GET('https://api.openf1.org/v1/laps?session_key=9161&driver_number=63&lap_number=8') parsed_data <- fromJSON(content(response, 'text')) print(parsed_data) # If you want, you can import the results in a DataFrame # df <- do.call(rbind, lapply(parsed_data, data.frame, stringsAsFactors = FALSE)) # df <- as.data.frame(t(as.matrix(df))) ``` -------------------------------- ### Retrieve Driver Information (JavaScript) Source: https://openf1.org/docs Fetch driver data using JavaScript's `fetch` API. The response is parsed as JSON and logged to the console. ```javascript fetch("https://api.openf1.org/v1/drivers?driver_number=1&session_key=9158") .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Get Race Control Data Source: https://openf1.org/docs This endpoint retrieves race control data based on specified filters such as flag type, driver number, and date range. ```APIDOC ## GET /v1/race_control ### Description Provides information about race control (session status, racing incidents, flags, safety car, ...). ### Method GET ### Endpoint /v1/race_control ### Parameters #### Query Parameters - **flag** (string) - Optional - Type of flag displayed (`GREEN`, `YELLOW`, `DOUBLE YELLOW`, `CHEQUERED`, ...). - **driver_number** (integer) - Optional - The unique number assigned to an F1 driver for the season. - **date** (string) - Optional - The UTC date and time, in ISO 8601 format. Supports comparison operators like `>=` and `<`. - **category** (string) - Optional - The category of the event (`SessionStatus`, `CarEvent`, `Drs`, `Flag`, `SafetyCar`, ...). - **lap_number** (integer) - Optional - The sequential number of the lap within the session (starts at 1), in a race. - **meeting_key** (integer or string) - Optional - The unique identifier for the meeting. Use `latest` to identify the latest or current meeting. - **message** (string) - Optional - Description of the event or action. - **qualifying_phase** (integer) - Optional - The specific phase (`1`, `2`, or `3`) if the session is a qualifying session. - **scope** (string) - Optional - The scope of the event (`Track`, `Driver`, `Sector`, ...). - **sector** (integer) - Optional - Segment ("mini-sector") of the track where the event occurred? (starts at 1). - **session_key** (integer or string) - Optional - The unique identifier for the session. Use `latest` to identify the latest or current session. ### Request Example ```bash curl "https://api.openf1.org/v1/race_control?flag=BLACK AND WHITE&driver_number=1&date>=2023-01-01&date<2023-09-01" ``` ### Response #### Success Response (200) - **category** (string) - The category of the event. - **date** (string) - The UTC date and time, in ISO 8601 format. - **driver_number** (integer) - The unique number assigned to an F1 driver for the season. - **flag** (string) - Type of flag displayed. - **lap_number** (integer) - The sequential number of the lap within the session. - **meeting_key** (integer) - The unique identifier for the meeting. - **message** (string) - Description of the event or action. - **qualifying_phase** (string or null) - The specific phase if the session is a qualifying session. - **scope** (string) - The scope of the event. - **sector** (integer or null) - Segment of the track where the event occurred. - **session_key** (integer) - The unique identifier for the session. #### Response Example ```json [ { "category": "Flag", "date": "2023-06-04T14:21:01+00:00", "driver_number": 1, "flag": "BLACK AND WHITE", "lap_number": 59, "meeting_key": 1211, "message": "BLACK AND WHITE FLAG FOR CAR 1 (VER) - TRACK LIMITS", "qualifying_phase": null, "scope": "Driver", "sector": null, "session_key": 9102 } ] ``` ``` -------------------------------- ### Fetch Car Data with JavaScript Source: https://openf1.org/docs This JavaScript snippet demonstrates fetching car data using the `fetch` API. It retrieves the response as JSON and logs it to the console. Ensure this code is run in an environment that supports the Fetch API. ```javascript fetch( "https://api.openf1.org/v1/car_data?driver_number=55&session_key=9159&speed>=315", ) .then((response) => response.json()) .then((jsonContent) => console.log(jsonContent)); ``` -------------------------------- ### Fetch Lap Data with cURL Source: https://openf1.org/docs Use this command to fetch lap data directly from the API using cURL. Ensure you replace placeholder values with actual session, driver, and lap numbers. ```bash curl "https://api.openf1.org/v1/laps?session_key=9161&driver_number=63&lap_number=8" ```