Pull today's UFC odds every morning in Python
A 50-line Python script that saves each UFC card's moneylines on fight day to a dated CSV, run every morning by GitHub Actions or cron.
Every script run against the live API on December 5, 2026. One full run: 12 credits.
FighterAPI has no player props, so the daily pull for the UFC is the fight moneylines. A card is on one day a week, and the price on the morning of the fights is gone by the first bell. A script that runs every morning and saves a file on fight days keeps that price. This guide builds it: a short Python script that finds the UFC bouts starting in the next 24 hours, pulls every sportsbook's moneylines for the whole card, and writes them to data/ufc_odds_<date>.csv. Then it runs the script for you every morning, with a GitHub Actions schedule or a cron line.
On a day with no card the schedule has nothing in the window, so the script saves nothing and spends 2 credits. For PFL or Bellator, pass league="pfl" or league="bellator" to both calls.
One full run on a fight day costs 12 credits: 2 for the schedule and 10 for the card, because a whole card is a flat 10 credits however many fights it holds (one fight alone is 5). A card whose lines are not posted yet costs nothing. The days with no card cost 2 each, so the run stays cheap through the weeks without a card.
1. Install the client and set your key
The client has no required dependencies, and the script below uses only the standard library. It needs Python 3.9 or newer, and the client reads your key from FIGHTERAPI_API_KEY. Put the key in the environment, never in the script.
pip install fighterapi
export FIGHTERAPI_API_KEY=your_key_here2. Write the script that saves today's odds
The script asks get_schedule for the next day, keeps the bouts that start in the next 24 hours (a bout with no start time set is skipped), and reads each card's odds with one get_odds call per card. Lines for a card appear once the sportsbooks post them. We check once a day, and every hour in the four days before the fights, so a run at 16:30 UTC on fight day holds the latest lines. Each day's window starts where the last one ended, so a card lands in one file, give or take the minutes a scheduled run can start late.
import csv
import time
from datetime import datetime, timedelta, timezone
from pathlib import Path
from fighterapi import Client
client = Client() # reads FIGHTERAPI_API_KEY
now = datetime.now(timezone.utc)
today = now.strftime("%Y-%m-%d")
COLUMNS = ["pulled_on", "event_id", "event_name", "bout_id", "starts_at", "weight_class", "title_fight", "scheduled_rounds", "fighter_a_name", "fighter_b_name", "provider", "a_open", "a_close", "a_current", "b_open", "b_close", "b_current", "a_close_prob", "b_close_prob", "total_rounds", "over_odds", "under_odds", "captured_at"]
def next_24_hours(rows, start_key):
"""Rows that start after now and no later than 24 hours from now."""
keep = []
for row in rows:
if row.get(start_key):
start = datetime.fromisoformat(row[start_key].replace("Z", "+00:00"))
if now < start <= now + timedelta(days=1):
keep.append(row)
return keep
bouts = next_24_hours(client.get_schedule(days=1)["bouts"], "starts_at")
events = sorted({b["event_id"] for b in bouts})
print(len(bouts), "bouts on", len(events), "card(s) start in the next 24 hours")
rows = []
for event_id in events:
card = client.get_odds(event_id=event_id) # the whole card, a flat price
for bout in card["bouts"]:
for book in bout["books"]:
rows.append({"pulled_on": today, **bout, **book})
time.sleep(1.1) # stay under 60 requests a minute
if rows:
Path("data").mkdir(exist_ok=True)
out = Path("data") / f"ufc_odds_{today}.csv"
with out.open("w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=COLUMNS, extrasaction="ignore")
writer.writeheader()
writer.writerows(rows)
print(len(rows), "lines saved to", out)
else:
print("nothing to save today")
print("credits left:", client.last_credits_remaining)Output
14 bouts on 1 card(s) start in the next 24 hours
99 lines saved to data/ufc_odds_2026-12-05.csv
credits left: 11114Save it as pull_ufc_odds.py and run it once by hand. It writes data/ufc_odds_<date>.csv, one file per day, and prints the credits left on the key that ran it. A day with nothing to save writes no file.
3. What each column means
Every row is one fight at one sportsbook. The columns, in file order:
- `pulled_on`: the UTC date the script ran. It is the same on every row of a file, which lets you stack the daily files.
- `event_id`, `event_name`: the card, such as
UFC 300. - `bout_id`: our id for the fight.
- `starts_at`: the fight's scheduled start, in UTC. Where the card has one start for every fight, it repeats.
- `weight_class`, `title_fight`, `scheduled_rounds`: the division, whether the belt is on the line, and the number of rounds scheduled.
- `fighter_a_name`, `fighter_b_name`: the two fighters, in the order the card lists them.
a_columns are fighter A,b_columns are fighter B. - `provider`: the sportsbook.
- `a_open`, `b_open`: the first moneyline we captured for each fighter, in American format (
-180,+155). - `a_current`, `b_current`: the latest moneyline before the fight.
- `a_close`, `b_close`: the closing moneyline. It may be empty before the fight, so read
a_currentandb_currentfor today's price. - `a_close_prob`, `b_close_prob`: the implied probability of the close, or of the current price when there is no close yet. It includes the sportsbook's margin, so the two do not sum to 1.
- `total_rounds`, `over_odds`, `under_odds`: the total-rounds line, such as 2.5, and the price of each side, where the sportsbook posts one.
- `captured_at`: when we captured the line, in UTC.
The prices are information about the market, not a forecast of the fight. A fight whose card has no lines posted yet has no rows, and the rest of the card is still saved. The card call returns every fight on the card, so a file can hold fights outside the 24-hour window, and a fight that was replaced (a new opponent after a withdrawal) can show as two bouts with the same fighter on both.
4. Run it every morning with GitHub Actions
Put the script in a private repository, add your key under Settings, Secrets and variables, Actions, and add this workflow as .github/workflows/daily-ufc-odds.yml. GitHub reads cron times as UTC and can start a scheduled run a few minutes late. The last step commits the new CSV, so the repository becomes your archive. Keep it private: the terms let you store this data but not redistribute it.
name: Daily UFC odds
on:
schedule:
- cron: "30 16 * * *" # 16:30 UTC every day
workflow_dispatch: # lets you run it by hand once to test
permissions:
contents: write
jobs:
pull:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install fighterapi
- run: python pull_ufc_odds.py
env:
FIGHTERAPI_API_KEY: ${{ secrets.FIGHTERAPI_API_KEY }}
- run: |
git config user.name "daily-pull"
git config user.email "daily-pull@users.noreply.github.com"
mkdir -p data
git add data/
git diff --cached --quiet || git commit -m "UFC odds $(date -u +%F)"
git pushRun it once from the Actions tab with the manual trigger before you trust the schedule. A failed run, such as a bad key or no credits, shows as a failed workflow and GitHub emails you.
5. Or run it from cron on your own machine
If you would rather keep the files local, one crontab line does the same job. Cron uses the machine's clock, so set the hour to 16:30 UTC in your own zone (11:30 on US Eastern time in winter). The key goes in a file only you can read, so it is not written into the crontab. Open the crontab with crontab -e.
# one-time setup
echo 'export FIGHTERAPI_API_KEY=your_key_here' > ~/.fighterapi_env && chmod 600 ~/.fighterapi_env
# crontab line: 16:30 every day, appends to a log
30 16 * * * cd ~/daily-pull && . ~/.fighterapi_env && python3 pull_ufc_odds.py >> pull.log 2>&1A laptop that is asleep at 16:30 skips the run, and cron does not catch up. On a machine that is not always on, use the GitHub workflow above.
6. Check the first file
Run the script by hand on a fight day and read the file it wrote. This prints the number of fights and sportsbooks, and each fight's current moneylines by book.
import glob
import pandas as pd
latest = sorted(glob.glob("data/ufc_odds_*.csv"))[-1]
df = pd.read_csv(latest)
print(latest, len(df), "rows,", df["bout_id"].nunique(), "fights,", df["provider"].nunique(), "sportsbooks")
print(df[["fighter_a_name", "fighter_b_name", "provider", "a_current", "b_current"]].head(10).to_string(index=False))Output
data/ufc_odds_2026-12-05.csv 99 rows, 16 fights, 7 sportsbooks
fighter_a_name fighter_b_name provider a_current b_current
Israel Adesanya Shara Magomedov BetMGM -165 135
Israel Adesanya Shara Magomedov BetOnline -160 136
Israel Adesanya Shara Magomedov Bovada -165 140
Israel Adesanya Shara Magomedov DraftKings -155 130
Israel Adesanya Shara Magomedov FanDuel -166 130
Israel Adesanya Shara Magomedov Pinnacle -139 119
Israel Adesanya Shara Magomedov theScore Bet (formerly ESPN BET) -170 140
Israel Adesanya Roman Kopylov BetMGM -180 145
Israel Adesanya Roman Kopylov BetOnline -170 145
Israel Adesanya Roman Kopylov Bovada -175 150One card on Dec 5 2026: 99 moneyline rows from 7 sportsbooks across the card's 16 fights.
After a few days, read the files together to see how a line moved from one morning to the next. Read them as a record of what the market showed, not as a forecast.
Tools and credits
- get_schedule: 1 call, 2 credits.
- get_odds: 1 call, 10 credits (10 credits for every card; one fight alone is 5).
One full run: 12 credits.
What you can do with the data
You may store these rows, train models and backtest on them, and build products that show your users what you derive. You may not redistribute the rows, or the prices as a raw feed, as a dataset or API of its own. Prices and lines are market information, not predictions or advice.
Details: data timing and rights.
What to do next
Start with 500 free credits every month
No card. pip install fighterapi, REST or MCP.