Developers
Boxing fight data in Python
Short answer. Request https://boxerbook.com/v1/schedule?when=30d with urllib or requests: no key, JSON back, each bout with both boxers, records, and where available the model probability and the market consensus. The four scripts below run as they are.
1. Model against market, no key
python · model_vs_market.py
"""Model against market for the next cards: where do the Boxerbook forecast and the market consensus differ?
One request, no key.
python3 model_vs_market.py
"""
import json, urllib.request
URL = "https://boxerbook.com/v1/schedule?when=30d"
with urllib.request.urlopen(urllib.request.Request(URL, headers={"User-Agent": "model-vs-market-example"}), timeout=30) as r:
schedule = json.load(r)
# forecast.p_a is the model, market.p_a the consensus with the margin removed; both are the probability of side a.
rows = [b for event in schedule["events"] for b in event["bouts"] if b.get("forecast") and b.get("market")]
rows.sort(key=lambda b: -abs(b["forecast"]["p_a"] - b["market"]["p_a"]))
print("%-10s %-42s %6s %7s %5s" % ("date", "bout", "model", "market", "gap"))
for b in rows:
model, market = b["forecast"]["p_a"], b["market"]["p_a"]
name = "%s vs %s" % (b["a"]["name"], b["b"]["name"])
print("%-10s %-42s %5.0f%% %6.0f%% %+5.0f" % (b["date"], name[:42], 100 * model, 100 * market, 100 * (model - market)))
print("Source: Boxerbook, %s (as of %s)" % (schedule["attribution"]["url"], schedule["as_of"]))2. Score a public sample
Accuracy and Brier score of the forecasts in the sample data set. On the file of 30 November 2026 it prints 61.5% for the rating and 75.0% for the model on 52 bouts.
python · dataset_sample.py
"""Score the pre-fight forecasts of the public sample: accuracy and Brier score, model against rating.
No key, no dependencies. Data: https://huggingface.co/datasets/Boxerbook/boxing-fight-model-sample
"""
import csv, io, urllib.request
URL = "https://huggingface.co/datasets/Boxerbook/boxing-fight-model-sample/resolve/main/prefight_forecasts.csv"
with urllib.request.urlopen(urllib.request.Request(URL, headers={"User-Agent": "dataset-sample-example"}), timeout=60) as r:
rows = list(csv.DictReader(io.StringIO(r.read().decode("utf-8"))))
done = [r for r in rows if r["winner"] in ("a", "b") and r["forecast_p_a"] and r["rating_p_a"]]
print("%d bouts in the file, %d with a winner" % (len(rows), len(done)))
for name, col in (("rating only", "rating_p_a"), ("model", "forecast_p_a")):
hits = sum((float(r[col]) > 0.5) == (r["winner"] == "a") for r in done)
brier = sum((float(r[col]) - (r["winner"] == "a")) ** 2 for r in done) / len(done)
print("%-12s winner picked %4.1f%% Brier %.3f" % (name, 100 * hits / len(done), brier))3. The signals of one bout
Needs a free key.
python · bout_signals.py
"""The pre-fight signals of one bout: what the forecast model reads for each corner.
export BOXERBOOK_API_KEY=... # free key: https://boxerbook.com/developers
python3 bout_signals.py 193203
"""
import json, os, sys, urllib.request
bout_id = int(sys.argv[1])
req = urllib.request.Request("https://boxerbook.com/v1/bouts/%d" % bout_id,
headers={"Authorization": "Bearer " + os.environ["BOXERBOOK_API_KEY"], "User-Agent": "bout-signals-example"})
with urllib.request.urlopen(req, timeout=30) as r:
bout = json.load(r)
signals = bout.get("signals") or {}
print("%s vs %s, %s" % (bout["a"]["name"], bout["b"]["name"], bout["date"]))
print("%-18s %14s %14s" % ("signal", "a", "b"))
for key in ("record", "age", "layoff_days", "last5", "ko_rate", "home", "stance", "height_cm", "reach_cm", "mu"):
print("%-18s %14s %14s" % (key, signals.get("a", {}).get(key), signals.get("b", {}).get(key)))
for name, block in (("rating only", {"p_a": signals.get("p_rating")}), ("model", bout.get("forecast")), ("market", bout.get("market"))):
if block and block.get("p_a") is not None:
print("%-18s P(a wins) = %.1f%%" % (name, 100 * block["p_a"]))
print("Cite:", bout["url"])4. Odds to probability
python · implied_probability.py
"""Odds to implied probability, with the margin removed. No network, no dependencies."""
def implied(odds):
"""Decimal odds (1.25), American odds ("-400", "+300") or fractional odds ("1/4") -> raw implied probability."""
s = str(odds).strip()
if "/" in s:
num, den = s.split("/")
return float(den) / (float(num) + float(den))
if s[0] in "+-":
v = float(s)
return 100 / (v + 100) if v > 0 else -v / (-v + 100)
return 1 / float(s)
def no_margin(*odds):
"""Probabilities of all outcomes of one bout, scaled to sum to 1 (the proportional method)."""
raw = [implied(o) for o in odds]
return [p / sum(raw) for p in raw]
if __name__ == "__main__":
a, b = no_margin("-400", "+300")
print("raw: %.1f%% + %.1f%% = %.1f%%" % (100 * implied("-400"), 100 * implied("+300"), 100 * (implied("-400") + implied("+300"))))
print("margin removed: %.1f%% / %.1f%%" % (100 * a, 100 * b)) # 76.2% / 23.8%More: developer quickstart · fields and files · keys and plans on boxerbook.com