#api #gaming #codemasters #f1


F1 API is a client library for the telemetry API of the F1 video games by Codemasters. It uses asynchronous networking to decode the incoming UDP packets, and turns them into strongly typed Rust structs.

1 unstable release

0.1.0 Mar 22, 2020

#8 in #gaming





A Rust implementation of the telemetry APIs of modern F1 video games.

This project implements a client library for the telemetry APIs that are provided by the current generation of F1 video games by Codemasters. The library is written in Rust, using tokio for async networking.

Built with ❤️ and 🦀 by Hello Bits.

Getting Started

Most of the library deals with the low-level details of receiving and decoding the packets that the F1 games sent. The only piece users need to interact with is the F1 struct and its high-level interface.

use f1_api::F1;
use f1_api::packet::Packet::{
    Event, Lap, Motion, Participants, Session, Setup, Status, Telemetry
use std::net::{IpAddr, SocketAddr};
use tokio::stream::StreamExt;

async fn main() {
    let ip_address = IpAddr::from([0, 0, 0, 0]);
    let port = 20777;
    let socket = SocketAddr::new(ip_address, port);

    let mut stream = F1::stream(socket).unwrap();

    while let Some(packet) = stream.next().await {
        match packet {
            Event(_) => println!("Received an Event packet"),
            Lap(_) => println!("Received a Lap packet"),
            Motion(_) => println!("Received a Motion packet"),
            Participants(_) => println!("Received a Participants packet"),
            Session(_) => println!("Received a Session packet"),
            Setup(_) => println!("Received aaSetup packet"),
            Status(_) => println!("Received a Status packet"),
            Telemetry(_) => println!("Received a Telemetry packet"),

F1::stream is an asynchronous function that returns a stream of incoming packets, and the recommended way to interface with the f1-api crate.


The examples folder contains examples that show how to use this library. For example, the code in the Getting Started section can be run with the following command:

cargo run --example readme

A more complex example is the cli, which uses the library to analyse incoming packets and print interesting information about the state of the game to the terminal. It can be run with:

cargo run --example cli


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~56K SLoC