br-g / openf1 Goto Github PK
View Code? Open in Web Editor NEWOpenF1 API - Real-time and historical Formula 1 data
License: MIT License
OpenF1 API - Real-time and historical Formula 1 data
License: MIT License
I've encountered an encoding issue when consuming the web service using the Flutter/Dart HTTP client. The client seems to default to latin1
encoding when the Content-Type
header lacks a specified charset, resulting in misinterpreted special characters.
This issue impacts any client that relies on the Content-Type
header to determine the correct character encoding. Since the Flutter/Dart HTTP client defaults to latin1
, it incorrectly decodes responses that include special characters, assuming the absence of a charset=utf-8
in the Content-Type
header.
To resolve this issue, I suggest explicitly setting the charset in the Content-Type
header for JSON responses. This can be implemented in the _process_api_query
function.
from fastapi.responses import JSONResponse
# Modify the _process_api_query function to return a JSONResponse with charset=utf-8
if not use_csv:
return JSONResponse(content=results, media_type="application/json; charset=utf-8")
else:
# Existing CSV handling logic
By specifying charset=utf-8 in the Content-Type header, clients like Flutter/Dart should correctly interpret the response encoding as UTF-8.
In the drivers table there seems to be two rows for the same driver_key
,meeting_key
& session_key
with some of the information like team_name
and headshot_url
missing from one row but not the other.
This can be seen in the CSV file
Aswell as the returned JSON from the endpoint https://api.openf1.org/v1/drivers?driver_number=77&meeting_key=1229&session_key=9466
Hi all,
all API responses have the wrong date format which does not comply with the ISO 8601 standard.
Now the dates are all without UTC information.
If no UTC relation information is given with a time representation, the time is assumed to be in local time.
Since dates are in UTC format, a Z
should be added at the end of the time.
2024-02-29T11:30:00
would be 2024-02-29T11:30:00Z
Thanks
I admit this might be a case of "garbage in, garbage out". But right now I'm getting this:
$ wget -qO - 'https://api.openf1.org/v1/drivers?driver_number=1&meeting_key=latest' | jq .
[
{
"session_key": 9481,
"meeting_key": 1231,
"broadcast_name": "M VERSTAPPEN",
"country_code": null,
"first_name": null,
"full_name": "Max VERSTAPPEN",
"headshot_url": null,
"last_name": null,
"driver_number": 1,
"team_colour": null,
"team_name": null,
"name_acronym": "VER"
},
{
"session_key": 9481,
"meeting_key": 1231,
"broadcast_name": "M VERSTAPPEN",
"country_code": null,
"first_name": null,
"full_name": "Max VERSTAPPEN",
"headshot_url": null,
"last_name": null,
"driver_number": 1,
"team_colour": null,
"team_name": null,
"name_acronym": "VER"
},
{
"session_key": 9482,
"meeting_key": 1231,
"broadcast_name": "M VERSTAPPEN",
"country_code": null,
"first_name": null,
"full_name": "Max VERSTAPPEN",
"headshot_url": null,
"last_name": null,
"driver_number": 1,
"team_colour": null,
"team_name": null,
"name_acronym": "VER"
},
{
"session_key": 9483,
"meeting_key": 1231,
"broadcast_name": "M VERSTAPPEN",
"country_code": "NED",
"first_name": "Max",
"full_name": "Max VERSTAPPEN",
"headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01.png.transform/1col/image.png",
"last_name": "Verstappen",
"driver_number": 1,
"team_colour": "3671C6",
"team_name": "Red Bull Racing",
"name_acronym": "VER"
},
{
"session_key": 9484,
"meeting_key": 1231,
"broadcast_name": "M VERSTAPPEN",
"country_code": "NED",
"first_name": "Max",
"full_name": "Max VERSTAPPEN",
"headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01.png.transform/1col/image.png",
"last_name": "Verstappen",
"driver_number": 1,
"team_colour": "3671C6",
"team_name": "Red Bull Racing",
"name_acronym": "VER"
},
{
"session_key": 9488,
"meeting_key": 1231,
"broadcast_name": "M VERSTAPPEN",
"country_code": null,
"first_name": null,
"full_name": "Max VERSTAPPEN",
"headshot_url": null,
"last_name": null,
"driver_number": 1,
"team_colour": null,
"team_name": null,
"name_acronym": "VER"
}
]
If I just did "session_key=latest" I'd get just the nulls for most of the fields.
In the team radio api, < https://api.openf1.org/v1/team_radio?date%3E=2024-01-01 >, all the recording_url in 2024 are started with "https://livetiming.formula1.com/static/2024/2024-03-02_Bahrain_Grand_Prix/2024-02-29_Practice_1/..." rather than it's own grand prix name and session name.
(Edit: adding a side question)
Side question: There seems no Australian GP radios ( meeting_key=1231 ) here, does the data source did not provide them or there was some problem occured? Any chance to re-catch them into the api database ?
Thanks ๐
In 2024, the data type for the team color in the drivers API has changed from string to int for some entries.
For instance, during the Bahrain Race on March 2nd, 2024, Fernando Alonso's team color is listed as an integer (229971), although other teams have their colors in hexadecimal format with letters, suggesting these should be strings.
https://api.openf1.org/v1/drivers?session_key=9472 (Bahrain Race in March 2nd, 2024)
{
"session_key": 9472,
"meeting_key": 1229,
"broadcast_name": "F ALONSO",
"country_code": "ESP",
"first_name": "Fernando",
"full_name": "Fernando ALONSO",
"headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/F/FERALO01_Fernando_Alonso/feralo01.png.transform/1col/image.png",
"last_name": "Alonso",
"driver_number": 14,
"team_colour": 229971,
"team_name": "Aston Martin",
"name_acronym": "ALO"
},
I would suggest serializing all team colors as strings for consistency.
Running the ingestor on any non POSIX/Unix platform results in a malformed URL and inability to parse the returned JSON. The specific error I get is as follows:
Traceback (most recent call last):
File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 196, in <module>
cli()
File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 1130, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\prest\OneDrive\Documents\Projects\openf1\.venv\Lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 178, in ingest_session
asyncio.run(_ingest_session(*args, **kwargs))
File "C:\Python312\Lib\asyncio\runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Python312\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python312\Lib\asyncio\base_events.py", line 685, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 149, in _ingest_session
session_path = get_session_path(year=year, meeting_key=meeting_key, session_key=session_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 85, in get_session_path
for meeting in _get_schedule(year)['Meetings']:
^^^^^^^^^^^^^^^^^^^
File "C:\Users\prest\OneDrive\Documents\Projects\openf1\ingestor\ingest_history.py", line 30, in _get_schedule
return json.loads(requests.get(url).content)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python312\Lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python312\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python312\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
After some debug printing, I discovered that the URL it was trying to get was https://livetiming.formula1.com/static\2023/Index.json
. The backslash is because the script uses os.path.join
to join the parts of the URL.
Driver API method for certain sessions return null driver properties, for example: https://api.openf1.org/v1/drivers?session_key=9152
Basically, going to https://api.openf1.org/v1/drivers?session_key=9480 (and all prev. sessions) shows that Kick Sauber's team colour is 5.2e+253. Don't know what's gone on here but it'd be good to check out to see what's gone on!
Not sure if it is a bug related to in-progress race weekends, but this URL
https://api.openf1.org/v1/meetings?year=2024
To get all meetings this year, is returning Shanghai twice (with the same meeting_key).
Hello,
I am trying to calculate the duration of one GP for each driver through the API Laps method summing up the "lap_duration" for each lap. However, I noticed that the "lap_duration" (and also the "duration_sector_1") is always null. Is this a bug? How can I reach the scope otherwise?
Here below an example:
{"meeting_key":1230,"session_key":9480,"driver_number":16,"i1_speed":280,"i2_speed":293,"st_speed":307,"date_start":null,"lap_duration":null,"is_pit_out_lap":false,"duration_sector_1":null,"duration_sector_2":29.838,"duration_sector_3":29.664,"segments_sector_1":[2048,2049,2049,2049,2051,2049,2051,2049,2049],"segments_sector_2":[2049,2049,2049,2049,2049,2049,2049],"segments_sector_3":[2051,2048,2048,2049,2048,2048,2048,2048,2049],"lap_number":1}
Many thanks in advance for any help.
When you request the CSV from https://api.openf1.org/v1/drivers?csv=true
some of the team colours are presented as 5.2e+253
I requested the raw JSON from the drivers endpoint using the following URI https://api.openf1.org/v1/drivers?driver_number=24&meeting_key=1229
and got this response
It looks like the data is held on the endpoint incorrectly - according to the documentation team_colour should be the six digit notation of the RGB team colour.
Weird bug when querying https://api.openf1.org/v1/meetings
The next-coming or current meeting
is part of the response when hitting that url with:
However, it is missing when querying with javascript fetch
. I don't remember the bug happening last time I worked on my project, so it could be related to current/ongoing
meeting as JPN GP is ongoing right now.
const response = fetch("https://api.openf1.org/v1/meetings")`;
return response.json();
...
{
"circuit_key": 149,
"circuit_short_name": "Jeddah",
"meeting_key": 1230,
"meeting_code": "KSA",
"location": "Jeddah",
"country_key": 153,
"country_code": "KSA",
"country_name": "Saudi Arabia",
"meeting_name": "Saudi Arabian Grand Prix",
"meeting_official_name": "FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024",
"gmt_offset": "03:00:00",
"date_start": "2024-03-07T13:30:00",
"year": 2024
},
{
"circuit_key": 10,
"circuit_short_name": "Melbourne",
"meeting_key": 1231,
"meeting_code": "AUS",
"location": "Melbourne",
"country_key": 5,
"country_code": "AUS",
"country_name": "Australia",
"meeting_name": "Australian Grand Prix",
"meeting_official_name": "FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024",
"gmt_offset": "11:00:00",
"date_start": "2024-03-22T01:30:00",
"year": 2024
}
]
...
{
"circuit_key": 149,
"circuit_short_name": "Jeddah",
"meeting_key": 1230,
"meeting_code": "KSA",
"location": "Jeddah",
"country_key": 153,
"country_code": "KSA",
"country_name": "Saudi Arabia",
"meeting_name": "Saudi Arabian Grand Prix",
"meeting_official_name": "FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024",
"gmt_offset": "03:00:00",
"date_start": "2024-03-07T13:30:00",
"year": 2024
},
{
"circuit_key": 10,
"circuit_short_name": "Melbourne",
"meeting_key": 1231,
"meeting_code": "AUS",
"location": "Melbourne",
"country_key": 5,
"country_code": "AUS",
"country_name": "Australia",
"meeting_name": "Australian Grand Prix",
"meeting_official_name": "FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024",
"gmt_offset": "11:00:00",
"date_start": "2024-03-22T01:30:00",
"year": 2024
},
{
"circuit_key": 46,
"circuit_short_name": "Suzuka",
"meeting_key": 1232,
"meeting_code": "JPN",
"location": "Suzuka",
"country_key": 4,
"country_code": "JPN",
"country_name": "Japan",
"meeting_name": "Japanese Grand Prix",
"meeting_official_name": "FORMULA 1 MSC CRUISES JAPANESE GRAND PRIX 2024",
"gmt_offset": "09:00:00",
"date_start": "2024-04-05T02:30:00",
"year": 2024
}
]
Is there ever a plan to format this as an https://npmjs.org package for use in Node.js without having to fetch URLs manually?
Whilst trying to retrieve data for the latest race I have come to notice that team color, team name, country code, first name, last name, interval data and pitstops aren't working properly. The driver data related fields are "none" for everyone, and the other two return an empty json when called.
Field "team_colour" should be hex string, but it is '5.2e+253' in team Kick Sauber
API request like this:
https://api.openf1.org/v1/drivers?session_key=9484
Result:
{
"session_key": 9484,
"meeting_key": 1231,
"broadcast_name": "G ZHOU",
"country_code": "CHN",
"first_name": "Guanyu",
"full_name": "ZHOU Guanyu",
"headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/G/GUAZHO01_Guanyu_Zhou/guazho01.png.transform/1col/image.png",
"last_name": "Zhou",
"driver_number": 24,
"team_colour": 5.2e+253,
"team_name": "Kick Sauber",
"name_acronym": "ZHO"
}
I'd love to make use of your API, I'm particularly interested in driver positioning and such but their coords aren't particularly useful without the CircuitInfo present, since the driver coordinates are relative to the CircuitInfo data. Would it be possible to integrate the FastF1 CircuitInfo data in to your API?
https://docs.fastf1.dev/circuit_info.html#fastf1.mvapi.CircuitInfo
Cheers
E.g.: https://api.openf1.org/v1/drivers?session_key=9473
(...)
{
"session_key": 9473,
"meeting_key": 1230,
"broadcast_name": "M VERSTAPPEN",
"country_code": null,
"first_name": null,
"full_name": "Max VERSTAPPEN",
"headshot_url": null,
"last_name": null,
"driver_number": 1,
"team_colour": null,
"team_name": null,
"name_acronym": "VER"
},
{
"session_key": 9473,
"meeting_key": 1230,
"broadcast_name": "M VERSTAPPEN",
"country_code": "NED",
"first_name": "Max",
"full_name": "Max VERSTAPPEN",
"headshot_url": "https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/M/MAXVER01_Max_Verstappen/maxver01.png.transform/1col/image.png",
"last_name": "Verstappen",
"driver_number": 1,
"team_colour": "3671c6",
"team_name": "Red Bull Racing",
"name_acronym": "VER"
},
(...)
Was reviewing my web application, designed to show race results for all the races in the season. I was validating the recent fixes made to the Drivers API, where some data was not coming for certain drivers and certain sessions.
I observed some inconsistencies in the team_colour variable for both Aston Martin drivers (note, I've only checked race sessions, possible there are other issues with other teams in other sessions).
If we look at Bahrain: https://api.openf1.org/v1/drivers?session_key=9472&driver_number%3E13&driver_number%3C20
and Jeddah: https://api.openf1.org/v1/drivers?session_key=9480&driver_number%3E13&driver_number%3C20
we can see that team_colour is coming as a string.
If we look at Australia and Japan
https://api.openf1.org/v1/drivers?session_key=9488&driver_number%3E13&driver_number%3C20
https://api.openf1.org/v1/drivers?session_key=9496&driver_number%3E13&driver_number%3C20
we can see that team_colour is coming as an integer.
Conveniently, due to the way I setup my filter, Charles Leclerc's data comes in and we can see his team_colour is always a string.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.