You can look up FMCSA carrier data in Python by calling the official QCMobile API with a DOT number and a free web key, then reading fields such as legal name, operating status and safety rating from the JSON response. It is more stable than scraping the SAFER website and is the better first choice when you only need public carrier records.
What data does the FMCSA make public?
The FMCSA publishes carrier registration and safety information, including legal name, DOT and MC numbers, operating status, address, power units and drivers. You request a free web key from the FMCSA developer portal. Check the current field list in the official documentation, because names can change.
How do you call the API?
import os
import requests
BASE = "https://mobile.fmcsa.dot.gov/qc/services/carriers"
KEY = os.environ["FMCSA_WEBKEY"]
def get_carrier(dot_number: int) -> dict | None:
r = requests.get(f"{BASE}/{dot_number}", params={"webKey": KEY}, timeout=20)
if r.status_code == 404:
return None
r.raise_for_status()
return r.json().get("content", {}).get("carrier")
carrier = get_carrier(1234567)
if carrier:
print(carrier.get("legalName"), carrier.get("allowedToOperate"))
How do you handle many carriers politely?
Add a small delay, retry on temporary errors, and cache results so you do not ask for the same DOT number twice.
import time, json, pathlib
from requests.exceptions import RequestException
CACHE = pathlib.Path("carriers.jsonl")
def fetch_many(dots, delay=0.5, retries=3):
for dot in dots:
for attempt in range(retries):
try:
data = get_carrier(dot)
with CACHE.open("a") as f:
f.write(json.dumps({"dot": dot, "carrier": data}) + "\n")
break
except RequestException:
time.sleep(2 ** attempt)
time.sleep(delay)
How do you validate and store the results?
Normalise the fields you need into a small dataclass or database table, and keep the raw JSON alongside it so you can re-parse if the schema changes. Record when each record was fetched, since carrier status changes over time.
When should you scrape instead?
Use the API first. Only fall back to browser automation for data the API does not expose, and always respect the site's terms and rate limits.
FAQ
Do I need an API key? Yes, the QCMobile API needs a free web key from the FMCSA.
Is FMCSA carrier data public? Registration and safety data is published by the FMCSA; check its terms for usage details.
Why a 404? The DOT number may not exist or may be mistyped.
How fresh is the data? It reflects FMCSA's records at query time, so store a fetch timestamp.
I build Python automation and data tools at INDUS Web Agency.
Top comments (0)