← All guides

Rider profile pages with career statistics

Combine a rider's profile and career totals into one profile card, keyed by race number.

8 min read

Fan apps, fantasy games and news sites all need a page per rider. Two calls give you everything for a profile card: the rider and their career totals.

The two calls

GET /riders/93
GET /riders/93/career-stats

/riders/{rider_number} returns the profile:

{
  "rider_number": 93,
  "full_name": "Marc Márquez",
  "nationality": "Spain",
  "flag": "🇪🇸",
  "birth_date": "1993-02-17",
  "height_cm": 168,
  "weight_kg": 59,
  "team_name": "Gresini Racing MotoGP",
  "image_url": null
}

/riders/{rider_number}/career-stats returns the totals:

{
  "rider_number": 93,
  "rider_name": "Marc Márquez",
  "total_wins": 44,
  "total_podiums": 66,
  "total_points": 1302,
  "world_titles": 2,
  "total_races": 118
}

Career totals are calculated from the seasons available in the API, not a rider’s whole career. Label them accordingly, for example “Since 2024”.

Fetch both in parallel

import os
from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass
from datetime import date

import requests

HOST = "motogp-api-championship-data-statistics.p.rapidapi.com"
HEADERS = {"X-RapidAPI-Key": os.environ["RAPIDAPI_KEY"], "X-RapidAPI-Host": HOST}


def get(path: str) -> dict:
    res = requests.get(f"https://{HOST}{path}", headers=HEADERS, timeout=10)
    res.raise_for_status()
    return res.json()["data"]


@dataclass(frozen=True)
class RiderCard:
    number: int
    name: str
    flag: str
    team: str
    age: int
    wins: int
    podiums: int
    titles: int
    races: int

    @property
    def podium_rate(self) -> float:
        return self.podiums / self.races if self.races else 0.0


def age_on(birth: str, today: date) -> int:
    born = date.fromisoformat(birth)
    return today.year - born.year - ((today.month, today.day) < (born.month, born.day))


def rider_card(number: int) -> RiderCard:
    with ThreadPoolExecutor(max_workers=2) as pool:
        profile_f = pool.submit(get, f"/riders/{number}")
        stats_f = pool.submit(get, f"/riders/{number}/career-stats")
        profile, stats = profile_f.result(), stats_f.result()
    return RiderCard(
        number=profile["rider_number"],
        name=profile["full_name"],
        flag=profile["flag"],
        team=profile["team_name"],
        age=age_on(profile["birth_date"], date.today()),
        wins=stats["total_wins"],
        podiums=stats["total_podiums"],
        titles=stats["world_titles"],
        races=stats["total_races"],
    )


card = rider_card(93)
print(f"{card.flag} #{card.number} {card.name} — {card.team}, {card.age}")
print(f"{card.wins} wins, {card.podiums} podiums in {card.races} races ({card.podium_rate:.0%})")

Build the index pages

Profile pages need a list to link from:

PageEndpoint
This season’s gridGET /riders/seasons/{year}?category=MOTOGP
Riders by countryGET /riders/nationality/{nationality} (e.g. Italy)
Every rider in the databaseGET /riders?page=1&size=200

Use rider_number as the URL slug (/riders/93/); it is what fans search for.

Handle missing data

  • image_url can be null. Show the race number in a coloured badge instead of a broken image.
  • A number that is not in use returns 404 — render a “rider not found” page rather than an error.
  • Riders sometimes change numbers between seasons. If you store favourites, store the number with the season it was taken from.
Next guide → Season calendar, next race and results