> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fieldfunded.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Live Sports Odds with Python

> Fetch live sports odds with Python in under 20 lines of code. Real-time data from 30+ sports using the FieldFunded API.

# Get Live Sports Odds with Python

Fetch real-time odds for any sport with Python in under 20 lines of code. This tutorial connects to the FieldFunded API, pulls live match odds, and prints them to your terminal — no web scraping, no browser automation, no rate limit headaches.

## Why Not Scrape?

Web scraping odds sites breaks constantly. Selectors change, CAPTCHAs appear, IP bans happen. An API gives you structured JSON with guaranteed uptime:

|             | Web Scraping               | FieldFunded API    |
| ----------- | -------------------------- | ------------------ |
| Setup time  | Hours (Selenium, proxies)  | 5 minutes          |
| Data format | Raw HTML to parse          | Clean JSON         |
| Reliability | Breaks weekly              | 99.9% uptime       |
| Legal risk  | Grey area (TOS violations) | Licensed data      |
| Rate limits | IP bans                    | 10K free req/month |

## Prerequisites

* Python 3.8+
* `requests` library (`pip install requests`)
* A free API key from [FieldFunded](https://fieldfunded.com/docs)

## Step 1: Get Your Free API Key

Sign up at [fieldfunded.com/docs](https://fieldfunded.com/docs) — no credit card required. Your key arrives in your inbox instantly.

## Step 2: Fetch Live Events

```python theme={null}
import requests

API_KEY = "your_api_key_here"
BASE_URL = "https://api.fieldfunded.com/v1"
HEADERS = {"X-API-Key": API_KEY}

# Get all currently live events
response = requests.get(f"{BASE_URL}/live", headers=HEADERS)
data = response.json()

print(f"{data['total']} live games right now\n")

for event in data["events"][:5]:
    print(f"{event['home_team']} vs {event['away_team']}")
    print(f"  Sport: {event['sport_key']}")
    print(f"  Score: {event.get('score', 'N/A')}")
    print()
```

Output:

```
12 live games right now

Manchester United vs Liverpool
  Sport: soccer_epl
  Score: 1-2

LA Lakers vs Boston Celtics
  Sport: basketball_nba
  Score: 89-94
```

## Step 3: Get Odds for a Specific Match

```python theme={null}
event_id = data["events"][0]["id"]

odds_response = requests.get(
    f"{BASE_URL}/events/{event_id}/odds",
    headers=HEADERS
)
odds = odds_response.json()

print(f"Markets available: {len(odds['markets'])}\n")

# Print Match Winner odds
for market in odds["markets"]:
    if "winner" in market["name"].lower() or "1x2" in market["name"].lower():
        print(f"--- {market['name']} ---")
        for selection in market["selections"]:
            print(f"  {selection['name']}: {selection['odds']}")
        break
```

Output:

```
Markets available: 847

--- Match Winner ---
  Manchester United: 3.40
  Draw: 3.60
  Liverpool: 2.10
```

## Step 4: Filter by Sport

```python theme={null}
# Get only soccer events
soccer = requests.get(
    f"{BASE_URL}/events",
    headers=HEADERS,
    params={"sport": "soccer"}
)
soccer_data = soccer.json()

print(f"{soccer_data['total']} upcoming soccer matches\n")

for event in soccer_data["events"][:3]:
    print(f"{event['home_team']} vs {event['away_team']}")
    print(f"  League: {event['league']}")
    print(f"  Kickoff: {event['commence_time']}")
    print()
```

## Step 5: Build a Simple Odds Monitor

Poll the API at intervals to track odds movements:

```python theme={null}
import time

def monitor_odds(event_id, interval=60):
    """Track odds changes for a specific event."""
    previous = {}

    while True:
        resp = requests.get(
            f"{BASE_URL}/events/{event_id}/odds",
            headers=HEADERS
        )
        odds = resp.json()

        for market in odds["markets"]:
            if "winner" not in market["name"].lower():
                continue

            for sel in market["selections"]:
                key = f"{market['id']}_{sel['id']}"
                current = sel["odds"]

                if key in previous and previous[key] != current:
                    direction = "↑" if current > previous[key] else "↓"
                    print(
                        f"{direction} {sel['name']}: "
                        f"{previous[key]} → {current}"
                    )

                previous[key] = current

        time.sleep(interval)

# Usage: monitor_odds("event_abc123", interval=30)
```

## Step 6: Settle a Bet Programmatically

After the match ends, check if a bet won:

```python theme={null}
settlement = requests.post(
    f"{BASE_URL}/bets/check",
    headers=HEADERS,
    json={
        "event_id": event_id,
        "market": "Match Winner",
        "selection": "Liverpool",
        "stake": 50,
        "odds": 2.10
    }
)
result = settlement.json()

print(f"Status: {result['status']}")  # won, lost, or refund
print(f"Payout: ${result.get('payout', 0)}")
```

## Rate Limit Math

| Use case                                            | Requests/day | Monthly | Plan           |
| --------------------------------------------------- | ------------ | ------- | -------------- |
| Check odds for 5 matches daily                      | 5            | 150     | Free           |
| Monitor 3 matches every 60s for 4 hours             | 720          | 21,600  | Free           |
| Full pipeline: events + odds + settlement           | 200          | 6,000   | Free           |
| Production bot with 10-min polling across 20 events | 2,880        | 86,400  | Starter (\$29) |

Most Python scripts fit comfortably in the [free tier](/compare/free-sports-api) — 10,000 requests/month with no credit card.

## Full Working Script

Here is everything combined into a single copy-paste script:

```python theme={null}
"""
live_odds.py — Fetch live sports odds with Python.
Requires: pip install requests
API Key:  https://fieldfunded.com/docs (free)
"""
import requests

API_KEY = "your_api_key_here"
BASE = "https://api.fieldfunded.com/v1"
H = {"X-API-Key": API_KEY}

# 1. Get live events
live = requests.get(f"{BASE}/live", headers=H).json()
print(f"=== {live['total']} LIVE GAMES ===\n")

for ev in live["events"][:5]:
    print(f"{ev['home_team']} vs {ev['away_team']} ({ev['sport_key']})")

    # 2. Get odds for this event
    odds = requests.get(f"{BASE}/events/{ev['id']}/odds", headers=H).json()
    print(f"  {len(odds['markets'])} markets available")

    # 3. Show match winner odds
    for m in odds["markets"]:
        if "winner" in m["name"].lower() or "1x2" in m["name"].lower():
            for s in m["selections"]:
                print(f"    {s['name']}: {s['odds']}")
            break
    print()
```

***

## Next Steps

* [Build a Settlement Engine](/guides/build-settlement-engine) — automate bet resolution after matches end
* [Build a Line Tracker](/guides/build-line-tracker) — track odds movements over time with visualizations
* [Build a Player Props Tracker](/guides/build-player-props-tracker) — monitor player-level markets
* [Free Sports API Comparison](/compare/free-sports-api) — see how the free tier compares

<CardGroup cols={2}>
  <Card title="Get Your Free API Key" icon="key" href="/quickstart">
    10,000 requests/month — no credit card required
  </Card>

  <Card title="TypeScript SDK" icon="code" href="/sdk">
    Prefer Node.js? Use the official SDK with full type safety
  </Card>
</CardGroup>
