The MOT History API client for Python and TypeScript

Look up every MOT test, mileage reading, defect and recall flag for any UK vehicle by registration or VIN, straight from the official DVSA MOT History API. OAuth handled, tokens cached, retries built in, and a clocking warning wherever the mileage went down.

Don't want to code? Run a free car check by reg at GetFreeCarCheck: MOT history, mileage, ULEZ, tax and recalls in seconds, no sign-up.

Everything the raw API makes you build yourself

The DVSA API needs an Entra ID token and an API key on every call, rate-limits hard and returns strings for numbers. This package deals with all of it so you can ship the feature.

OAuth2 done for you

Client-credentials token fetched once, cached for its 60 minutes, refreshed on 401. Concurrent JavaScript calls share one token request.

Retries that respect limits

429 and 5xx retried with Retry-After and exponential backoff. Typed errors for not found, invalid, auth and rate limits.

Clocking warnings

Odometer readings in miles (kilometres converted), average miles a year, and a flag wherever the mileage went down between tests.

Typed models

Frozen dataclasses for vehicle, test and defect in Python; full .d.ts types in TypeScript. Dates parsed, strings cleaned.

Runs everywhere

Python standard library only. JavaScript is one fetch-based file for Node 20+, Cloudflare Workers, Deno and Bun.

A handy CLI

uk-mot-history AB12CDE prints a readable history: results, mileage, advisories and failures, MOT expiry and recall status.

Quick start

Install from GitHub, set four environment variables from your DVSA email, and look up a car.

Python
uv add git+https://github.com/behoss/uk-mot-history

from uk_mot_history import MotHistoryClient, find_mileage_anomalies

client = MotHistoryClient.from_env()       # MOT_HISTORY_* variables
car = client.by_registration("AB12 CDE")   # or client.by_vin(...)

print(car.make, car.model, "MOT expires", car.mot_expiry)
for test in car.mot_tests:                 # newest first
    print(test.completed_date.date(), test.test_result, test.odometer_miles)
for warning in find_mileage_anomalies(car):
    print("Clocking warning:", warning)
TypeScript / JavaScript
// copy js/src/index.js + index.d.ts into ./mot/
import { MotHistoryClient, findMileageAnomalies, motExpiry } from "./mot/index.js";

const client = MotHistoryClient.fromEnv(env); // Workers env or process.env
const car = await client.byRegistration("AB12CDE");

console.log(car.make, car.model, "MOT expires", motExpiry(car));
for (const a of findMileageAnomalies(car)) {
  console.log(`Mileage fell ${a.drop} miles by ${a.later.date}`);
}
CLI
$ uk-mot-history AB12CDE
FORD FOCUS  (AB12CDE)
Silver | Petrol | 1596 cc | first used 2012-03-01
MOT expires: 2025-02-28 (valid)
Outstanding recall: No

2024-02-27  PASS  71,240 mi
            ADVISORY   Nearside Front Tyre worn close to legal limit/worn on edge (5.2.3 (e))
2023-02-20  PASS  58,410 mi
2022-02-24  FAIL  61,002 mi
            MAJOR      Offside Rear Brake pipe excessively corroded (1.1.11 (c))
            DANGEROUS  Nearside Front Suspension arm ball joint excessively worn (5.3.4 (a) (i))
2021-02-25  PASS  49,870 mi

WARNING: mileage went down by 2,592 miles: 61,002 on 2022-02-24 -> 58,410 on 2023-02-20 (possible clocking)
Average: 7,115 miles a year.

Sample output from the test fixture; the registration is made up.

Get a DVSA MOT History API key

The API is free. DVSA issues keys to organisations, businesses and individuals.

  1. Read DVSA's MOT History API registration page, then fill in the registration form (name, email, postal address).
  2. Review takes up to five working days. DVSA emails a client ID, client secret, API key and the tenant ID for the token URL.
  3. Put them in environment variables, never in code. Keys from the old, pre-OAuth MOT History API don't work: register again.
VariableFrom the DVSA email
MOT_HISTORY_CLIENT_IDClient ID
MOT_HISTORY_CLIENT_SECRETClient secret
MOT_HISTORY_API_KEYAPI key, sent as X-API-Key
MOT_HISTORY_TENANT_IDTenant ID in the Microsoft token URL

API notes and gotchas

What the DVSA documentation leaves you to find out the hard way.

  • Two credentials on every call: a bearer token (client credentials, scope https://tapi.dvsa.gov.uk/.default) and the X-API-Key header. Missing either gives 401 or 403.
  • Rate limits: 500,000 requests a day, 15 a second on average, bursts of 10. Go over the daily quota and the key is blocked for 24 hours, so cache results on your side.
  • Two response shapes: a car with tests has motTests; a car too new for its first MOT has none and a motTestDueDate instead. mot_expiry and motExpiry() handle both.
  • Odometer values are strings with a unit (MI or KM) and a result type (READ, UNREADABLE, NO_ODOMETER). Use the miles helpers rather than the raw value.
  • Defect types: ADVISORY, MINOR, MAJOR, DANGEROUS, plus FAIL, PRS and USER ENTERED on older records. Same-day retests appear as separate tests.
  • Mileage drops are the classic clocking sign; a tester's typo or a replaced instrument cluster can cause them too, so treat them as a flag to investigate.
  • Bulk data: bulk_download() returns short-lived links to the full extract and daily deltas. Download them straight away.
  • Licence: the data is under the Open Government Licence v3.0. Show "Contains public sector information licensed under the Open Government Licence v3.0." wherever you display it.

Open data: first-MOT fail rates by make and model

The repo also ships a CSV of first-MOT fail rates for 350 makes and models, from 7.3 million first MOTs (2022 to 2024) in DVSA's open MOT data, each row linked to that model's reliability page. See the ranked tables on cars most likely to fail their first MOT, or download the CSV.