Metadata-Version: 2.5
Name: ufcalendar
Version: 0.12.0
Summary: MMA Fight Data API client for Python — UFC, PFL, OKTAGON, BKFC, RIZIN, KSW events, fight stats, results, rankings history, judges' scorecards, consensus odds and a live fight-night WebSocket.
Project-URL: Homepage, https://www.ufcalendar.com/developers
Project-URL: Free plan, https://www.ufcalendar.com/account/api?trial=1
Project-URL: Reference and examples, https://mmadataapi.com/sdks/python
Project-URL: Documentation, https://api.ufcalendar.com/docs
Project-URL: UFC data coverage, https://www.ufcalendar.com/developers/ufc-api
Project-URL: OpenAPI spec, https://api.ufcalendar.com/openapi.json
Project-URL: Source, https://github.com/UFCalendar/ufcalendar-python
Project-URL: Issues, https://github.com/UFCalendar/ufcalendar-python/issues
Author-email: UFCalendar <api@ufcalendar.com>
License: MIT
License-File: LICENSE
Keywords: api,bkfc,consensus-odds,fight-api,fight-data,ksw,live-mma-data,live-stream,mcp,mcp-server,mma,mma-api,mma-fight-data-api,mma-mcp,mma-odds,mma-stats,oktagon,pfl,rankings,rizin,sports-data,ufc,ufc-api,ufc-live-stats,ufc-rankings,ufc-scorecards,ufc-stats,websocket
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: requests>=2.28
Provides-Extra: live
Requires-Dist: websocket-client>=1.7; extra == 'live'
Description-Content-Type: text/markdown

# ufcalendar — MMA Fight Data API client for Python

UFC, PFL, OKTAGON, BKFC, RIZIN and KSW events, fight stats, results, rankings history and judges' scorecards from one Python client.

The [MMA Fight Data API by UFCalendar](https://www.ufcalendar.com/developers) (the UFCalendar Fight API) is a REST API for MMA data: **UFC, PFL, OKTAGON, BKFC, RIZIN and KSW** events, full fight cards, results within minutes, per-fight and round-by-round statistics, complete fighter careers, the only **MMA data API with point-in-time UFC rankings history back to 2013**, and the only one serving **judges' scorecards** — every official, every round: UFC back to 1995, PFL to 2018, OKTAGON to 2025 and RIZIN 2019–2022 and from March 2026 — plus the **UFCalendar consensus odds line** (current, opening and closing on every plan, line movement on Pro) and, on Pro and Business, a **live fight-night WebSocket** for UFC cards. This package is a thin `requests` wrapper over it — one method per endpoint, cursor pagination handled for you.

```bash
pip install ufcalendar
```

Reference with real responses and every method: https://mmadataapi.com/sdks/python

Get a free key at https://www.ufcalendar.com/account/api?trial=1 — the free plan is 100 requests a month, no card, never expires. Paid plans from $19/month for 30,000 requests (Pro $49 for 200,000, Business $149 for 1,000,000), hard caps, no overage.

## Quickstart in 3 lines

```python
from ufcalendar import FightAPI
api = FightAPI("ufcalendar_...")                       # free-plan key, no card
print(next(api.events(org="ufc", limit=1))["title"])   # the next UFC card
```

## Quickstart

```python
from ufcalendar import FightAPI

api = FightAPI("ufcalendar_...")            # or export UFCALENDAR_API_KEY=...

# Upcoming UFC schedule, soonest first
for ev in api.events(org="ufc", limit=5):
    print(ev["starts_at"], ev["title"], "PPV" if ev["is_ppv"] else "")

# Full card + results of the newest completed UFC event
latest = next(api.events(org="ufc", status="completed", limit=1))
card = api.event(latest["slug"])
for f in card["card"]:
    r = f.get("result")
    if r:
        print(f["fighter_a"]["name"], "vs", f["fighter_b"]["name"], "->", r["method"], f"R{r['round']} {r['time']}")

# Round-by-round statistics for one bout
rounds = api.fight_rounds(card["card"][0]["id"])

# UFC rankings on any date since February 2013 (rank 0 = champion)
board = api.rankings("ufc", date="2016-11-14")
lw = next(d for d in board["divisions"] if d["division"] == "lightweight")
print(board["snapshot_date"], [e["name"] for e in lw["entries"][:5]])

# A fighter's complete multi-promotion career
history = api.fighter_history("islam-makhachev")
```

## What's covered

| Method | Endpoint |
|---|---|
| `plans()` | `GET /v1/plans` — plans (Free first), quotas, free-plan terms, MCP endpoint (no key required) |
| `events(org, status, from_date, to_date, order, is_title_card, is_ppv, include=["headline"])` | `GET /v1/events` (paginated; `headline` = each card's main event and its result) |
| `event(slug, include=["eta", "odds"])` / `event_changes(slug)` | `GET /v1/events/{slug}` / `…/changes` (`eta` = per-bout estimated start; `odds` = each bout's latest consensus line) |
| `event_watch(slug, country)` | `GET /v1/events/{slug}/watch` — how to watch one event, per country: the rights deals for its series merged with the event's own listings |
| `changes(org, since, kind)` | `GET /v1/changes` — the card-change feed across every event, newest first (paginated; default last 90 days) |
| `event_live(slug)` | `GET /v1/events/{slug}/live` — the live fight-night document of a UFC card (Contender Series included): bout order and statuses, the bout in progress (round, running clock, unofficial in-fight stats, per-round splits, a timestamped action timeline) and the last result; `None` when the card is not live. Pro and Business plans |
| `live_stream(slug, until_final)` | the **WebSocket** `wss://live.ufcalendar.com/v1` — subscribe to a card and iterate every frame as it changes (`pip install 'ufcalendar[live]'`; Pro and Business plans) |
| `fight(id, include=["odds"])` / `fight_stats(id)` / `fight_rounds(id)` | `GET /v1/fights/{id}` / `…/stats` / `…/rounds` (`fight_stats` lines carry `fantasy` — UFCalendar fantasy points with a per-category breakdown; `last_meta["quality"]` = data-quality flags) |
| `fight_odds(id)` / `event_odds(slug)` | `GET /v1/fights/{id}/odds` / `GET /v1/events/{slug}/odds` — the UFCalendar consensus line: current, opening, closing (settled bouts), movement and `sources` (how many sportsbooks backed each point), plus `props` (method of victory per corner, total rounds over/under, goes the distance). Information only, not betting advice |
| `fight_odds_history(id, from_date, to_date)` | `GET /v1/fights/{id}/odds/history` — every consensus point, oldest first (paginated; Pro plans and up) |
| `find_fights(org, title_only, method, division, fighter, winner, from_date, to_date, main_events_only, order)` | `GET /v1/fights/search` — completed bouts, filtered, newest first (at least one narrowing filter; 25 a page, 10 pages deep) |
| `fight_scorecards(id)` | `GET /v1/fights/{id}/scorecards` — judges, rounds, totals, deductions |
| `fight_timeline(id)` / `fight_positions(id)` | `GET /v1/fights/{id}/timeline` / `…/positions` — settled UFC bouts: the official in-fight log (every action, referee stoppages with their reason and real length, every confirmed foul and the foul counts per corner; from June 2013, stoppage reasons from 8 December 2018) and position stats for the bout and each round (time at distance / in the clinch / on the ground, control by position, strikes by position and target; from 2007). Pro plans and up |
| `judges(q, org, min_fights)` / `judge(id)` / `judge_scorecards(id)` | `GET /v1/judges` / `…/{id}` / `…/{id}/scorecards` (`last_meta["league"]` = baseline rates; each card row flags `lone_dissent` / `split` and lists `colleagues`) |
| `split_decisions(org, from_date, to_date)` | `GET /v1/scorecards/splits` — split and majority decisions, newest first, with every judge's card and the dissenters named (paginated) |
| `referees(q, org)` / `referee(slug)` / `referee_fights(slug)` | `GET /v1/referees` / `…/{slug}` / `…/{slug}/fights` — referees across the launch promotions: bouts, finish rate, method mix, average fight time; the bouts each one worked (paginated) |
| `coverage(org)` | `GET /v1/coverage` — what the database holds per promotion per year: events, settled bouts, and the share with stats, round stats, commission scorecards and a consensus odds line |
| `fighters(q, org, country, roster_status)` / `fighter(slug, include=["bonuses", "credentials"])` | `GET /v1/fighters` / `…/{slug}` (every fighter carries `roster` — the promotion's own published roster status: `active`, `off_roster` = no longer listed, `retired`; `roster_status` needs `org="ufc"`; the profile always carries `next_fight` / `last_fight`; `bonuses` = the UFC bonus ledger; `credentials` = grappling and wrestling pedigree, gyms and coaches, each row sourced and confidence-graded) |
| `fighter_history` / `fighter_stats` / `fighter_rankings` / `fighter_power_index` | `GET /v1/fighters/{slug}/…` |
| `fighter_discipline(slug)` / `fighter_positions(slug)` | `GET /v1/fighters/{slug}/discipline` / `…/positions` — the confirmed fouls in a fighter's UFC bouts, committed and drawn (eye pokes and low blows from the official in-fight log, plus any other foul confirmed by the athletic commission's point deduction or by the official result; counts by kind, points deducted, every incident), and the career position profile (share of cage time by range, control for and against by position). `None` under 3 tracked bouts. Pro plans and up |
| `rankings(org, date)` / `division_rankings(org, division)` / `champions()` | `GET /v1/rankings/…` / `/v1/champions` (entries carry `movement`, `is_new`, `country_code`; `last_meta` names the previous/next snapshot) |
| `power_index(org, view, division, days, limit)` / `predictions_upcoming(event)` | `GET /v1/power-index/{org}` (`view`: `current` · `movers` · `peaks`) / `/v1/predictions/upcoming` |
| `roster(org, status, division)` / `roster_moves(org, since, until, kind, fighter)` | `GET /v1/rosters/{org}` / `…/moves` — the UFC roster as published by the promotion (division, since, last bout, next booking; paginated), and the confirmed moves: signings, departures (no longer listed on the roster), retirements and returns, each dated by the window it happened in. Pro plans and up |
| `matchmaker(org, division, limit)` / `whos_next(fighter, limit)` | `GET /v1/matchmaker/{org}` / `…/next/{fighter}` — UFCalendar's matchmaker: the fights worth making (scored 0–100, per division or across the roster; not bookings), and one fighter's best next opponents with the win probability for each and the bout already booked |
| `leaderboard(org, metric, division, country, population, limit)` / `record_book(org, division, country, population, scope, top)` | `GET /v1/stats/leaders` / `…/record-book` — the Record Book: one leaderboard (57 metrics (9 discipline boards need Pro+); ties flagged, sample size on every row), or every board's top rows grouped by category |
| `org_division(org, division)` | `GET /v1/orgs/{org}/divisions/{division}` — one weight class: rankings board, upcoming bouts, latest results, roster by recency |
| `year_stats(year, org)` | `GET /v1/stats/years/{year}` — one calendar year in numbers for one promotion (or every covered one): methods, divisions, fastest finishes, upsets, Power Index climbers, busiest fighters, countries, judges |
| `compare(a, b)` | `GET /v1/compare` — two fighters side by side: bios, career stats, strike mix, streaks, previous meetings, common opponents, booked bout, model prediction (UFC), Power Index |
| `event_storylines(slug)` | `GET /v1/events/{slug}/storylines` — the talking points of one card: title fights, eliminators, closest bout, rematches, streaks, debuts, returns, ranked fighters, nations |
| `event_pickem(slug)` | `GET /v1/events/{slug}/pickem` — how the UFCalendar community is picking each bout on one card (picks per corner, total, percentage); crowd sentiment, not a market and not a forecast |
| `broadcast_rights(org, country, series)` / `venue(id)` / `search(q)` / `usage()` | misc (`series="dwcs"`/`"rtufc"` = a UFC sub-series grid) |
| `venues(q, country)` / `venue_events(id, status, from_date, to_date, order)` | `GET /v1/venues` / `…/{id}/events` — venue search, and every covered event at one venue, newest first (paginated) |
| `articles(q, tag, locale)` / `article(slug, locale)` | `GET /v1/articles` / `…/{slug}` — UFCalendar's own editorial archive, newest first, in any of the 13 site languages (paginated), and one article's full Markdown body |
| `create_webhook_endpoint(url, events)` … | `POST /v1/webhook-endpoints` (Pro+; kinds `event.announced`, `fight.result`, `card.changed`, `event.completed`, `odds.moved`, `roster.changed`) |
| `calendar_ics_url(org)` | `GET /v1/calendar/{org}.ics` |

Full reference: https://api.ufcalendar.com/docs · OpenAPI 3.1: https://api.ufcalendar.com/openapi.json · Also on [npm (TypeScript client)](https://www.npmjs.com/package/@ufcalendar/sdk), [RapidAPI Hub](https://rapidapi.com/ceo-SP8r6F1JT/api/ufc-and-mma-fight-data-by-ufcalendar), [Postman](https://www.postman.com/ceo-5d84eedc/workspace/ufcalendar-fight-api) and the [hosted MCP server](https://github.com/UFCalendar/ufcalendar-mcp)

## Consensus odds

```python
o = api.fight_odds(83379)
print(o["consensus"]["a"]["american"], o["consensus"]["b"]["american"], o["consensus"]["sources"])
print(o["movement"]["delta_points_a"], o["closing"])   # closing = last line before the start (settled bouts)

for point in api.fight_odds_history(83379):               # Pro plans and up
    print(point["recorded_at"], point["a"]["american"], point["b"]["american"])
```

One anonymised UFCalendar consensus line per corner across the sportsbooks we track;
book identities are never exposed. Information only, not betting advice.

## Fight log and position stats (Pro and up)

```python
log = api.fight_timeline(59652)                 # UFC 286, Edwards vs Usman
for s in log["stoppages"]:                      # every referee stoppage; is_foul says if a record confirms a foul
    print(s["round"], s["elapsed_sec"], s["reason"], s["duration_sec"], s["is_foul"], s["foul"], s["foul_basis"])
for i in log["incidents"]:                      # every confirmed foul, in fight order
    print(i["foul"], i["basis"], i["committed_by"], i["points_deducted"], i["ended_bout"])
print(log["fouls"]["a"])                         # what corner a committed: eye_pokes, low_blows, other, total, points_deducted

pos = api.fight_positions(59652)
a = pos["totals"][0]
print(a["time"]["distance_sec"], a["time"]["clinch_sec"], a["time"]["ground_sec"], a["control"]["total_sec"])

d = api.fighter_discipline("leon-edwards")       # None under 3 tracked bouts
print(d["committed"], d["points_deducted"], d["fouls_per_15"], len(d["incidents"]))
for i in d["incidents"]:                         # reason is the foul; basis is the record behind it
    print(i["date"], i["role"], i["reason"], i["basis"], i["points_deducted"], i["ended_bout"])
p = api.fighter_positions("leon-edwards")
print(p["time"]["distance_share"], p["control"]["for_sec"], p["control"]["against_sec"])
```

Settled UFC bouts only (Contender Series included): the log from June 2013, stoppage
reasons from 8 December 2018, positions reliably from 2007.

Fouls are confirmed fouls. The log labels only two, the eye poke and the low blow; any
other foul (an illegal knee to a grounded opponent, an upkick, a headbutt, a bite, a fence
grab) reaches it as a `generic` stoppage naming nobody, so it is reported only when a
record confirms it: `log` (the labelled row), `deduction` (the athletic commission took a
point) or `result` (the bout ended on it: a disqualification or a "could not continue").
A `generic` stoppage with no record behind it has `is_foul` false. The fighter on a foul
is the one who committed it. A recorded foul is not a ruling on intent.

In position stats `None` means not tracked for that bout and `0` is a real zero. Below Pro these raise
`FightAPIError` 403 `tier_required`.

## Webhooks instead of polling (Pro and up)

```python
ep = api.create_webhook_endpoint("https://example.com/hooks/ufcal", ["fight.result", "card.changed"])
print(ep["secret"])   # shown once; verify X-UFCalendar-Signature with it
```

`odds.moved` fires when the consensus line on an upcoming bout moves 5+ implied-probability
points on corner a, or the favourite flips, measured against the last line delivered, so a
slow drift arrives once. Information only, not betting advice.

`roster.changed` fires once per confirmed UFC roster move (signed, left the roster, retired,
returned), as published by the promotion; `data` is the same object `roster_moves()` yields.

## Live fight night (Pro and Business)

On a UFC fight night (Contender Series included) the API serves one live document per
card: bout order and statuses, the bout in progress (phase, round, running clock,
unofficial in-fight stats, per-round splits and a timestamped action timeline) and the
last result. Read it once with `event_live()`, or let the WebSocket push it to you on
every change instead of polling.

The socket ships as an optional extra so a REST-only install stays `requests`-thin:

```bash
pip install 'ufcalendar[live]'
```

```python
from ufcalendar import FightAPI

api = FightAPI()  # UFCALENDAR_API_KEY

snap = api.event_live("ufc-331")                # None when the card is not live

for frame in api.live_stream("ufc-331", until_final=True):
    # frame["type"]: "snapshot" | "update" | "fight.final" | "event.completed" | "error"
    state = frame.get("data")
    if not state:
        continue                      # nothing streaming yet
    cur = state["current"] or {}
    print(frame["type"], "R", cur.get("round"), cur.get("clock_sec"))
```

Under the hood: connect to `wss://live.ufcalendar.com/v1?key=<key>`, send
`{"action": "subscribe", "event": "<slug or id>"}`, and every frame is
`{"type": …, "data": <LiveState>}` (`{"action": "ping"}` answers `{"type": "pong"}`).
`until_final=True` stops after the first `fight.final` frame; the default runs until
the socket ends. A dropped connection is re-subscribed once automatically. A Pro key
may hold 2 sockets at once, a Business key 5; below Pro `event_live()` raises
`FightAPIError` 403 `tier_required` and the socket upgrade is refused.

In-fight numbers are unofficial. The official result and totals land on `fight(id)` /
`fight_stats(id)` when the bout is settled.

Runnable ticker: [`examples/live_ticker.py`](examples/live_ticker.py) prints
`R2 3:41 · Oliveira 41 vs Makhachev 37 sig. strikes` as the round unfolds.

## Errors and rate limits

Every error raises `FightAPIError` with `.status`, `.code`, `.message`, `.request_id`. After each call `api.last_rate_limit` holds the `X-RateLimit-*` headers.

Rate-limited reads are waited out for you. When a `GET` hits the per-minute limit (429
`rate_limited`, `Retry-After` of 60 s or less; the free plan allows 10 requests a minute) the
client sleeps for `Retry-After` plus a little jitter and tries again, up to `max_retries` times
(default 3), so a script that walks a few pages does not die mid-run. A 429'd request does not
count against your month.

```python
api = FightAPI("ufcalendar_...", max_retries=5)   # wait out more per-minute 429s
api = FightAPI("ufcalendar_...", max_retries=0)   # never wait: raise FightAPIError on the first 429
```

The monthly quota (429 `quota_exceeded`), a 429 with a long or missing `Retry-After`, and every
non-`GET` request (webhook endpoint create / delete / rotate) raise `FightAPIError` at once.

## Notes

- Odds are the UFCalendar consensus line only (no book identities). Information only, not betting advice.
- Fighter `images` are Wikimedia Commons / Creative Commons files: display the `license` and `artist` fields as a credit.
- UFCalendar is an independent data aggregator, not affiliated with, endorsed by or licensed by UFC, Zuffa, TKO or any promotion. Data is compiled from publicly accessible sources and is not an official or rights-cleared feed. Terms: https://www.ufcalendar.com/developers/terms

MIT licensed.
