Skip to content

Latest commit

 

History

History

examples

README.md

Examples

This directory contains example scripts demonstrating how to use the Odds-API.io Python SDK.

Getting Started

Before running the examples, make sure you have:

  1. Installed the SDK:

    pip install odds-api-io
  2. Obtained an API key from odds-api.io

  3. Set your API key as an environment variable:

    export ODDS_API_KEY="your_api_key_here"

    Or modify the examples to use your API key directly.

Available Examples

1. Basic Usage (basic_usage.py)

Learn the fundamentals of the SDK:

  • Initializing the client
  • Getting sports and leagues
  • Fetching events
  • Searching for games
  • Working with bookmakers
python basic_usage.py

2. Async Client (async_example.py)

Use the async client for concurrent operations:

  • Async/await syntax
  • Concurrent requests with asyncio.gather
  • Async context managers
python async_example.py

3. Arbitrage Finder (arbitrage_finder.py)

Find arbitrage betting opportunities:

  • Discovering risk-free betting opportunities
  • Comparing odds across bookmakers
  • Calculating potential profits
python arbitrage_finder.py

4. Value Bets (value_bets.py)

Identify value betting opportunities:

  • Finding positive expected value bets
  • Understanding implied vs true probability
  • Analyzing betting edges
python value_bets.py

5. Odds Tracking (odds_tracking.py)

Track odds movements over time:

  • Monitoring odds changes
  • Historical odds data
  • Batch odds fetching
  • Recent updates tracking
python odds_tracking.py

6. Fair odds and closing lines (fair-odds-and-closing-lines.ipynb)

A Jupyter notebook, viewable without running anything at nbviewer.org/github/odds-api-io/odds-api-python/blob/main/examples/fair-odds-and-closing-lines.ipynb:

  • Devigging with the multiplicative and power methods
  • Bookmaker margin per fixture on moneyline and spread markets, from a real /odds/multi snapshot of six bookmakers
  • Expected value of every soft-book price against the sharp consensus fair line
  • Closing lines for a week of settled Premier League matches from /historical/closing-lines
  • Closing line value and a line-movement chart from /odds/movements

It runs with plain requests, pandas and matplotlib (no SDK needed). With ODDS_API_KEY set it fetches live data; without a key it uses the frozen snapshot in data/snapshot-2026-09-19.json, so every cell runs offline.

pip install jupyter requests pandas matplotlib
jupyter notebook fair-odds-and-closing-lines.ipynb

7. Bookmaker guides (bet365_odds.py, betfair_exchange_odds.py, draftkings_odds.py)

One short script per bookmaker, each paired with a guide on the blog:

  • bet365_odds.py: Bet365 1X2 and the 2.5 goal line for the next Premier League fixtures (guide)
  • betfair_exchange_odds.py: Betfair Exchange back and lay prices, the gap between them and the midpoint (guide)
  • draftkings_odds.py: DraftKings NFL moneyline, spread and total, converted to American odds (guide)

Add the bookmaker to your selected bookmakers before running its script.

python bet365_odds.py
python betfair_exchange_odds.py
python draftkings_odds.py

8. Bet settlement (settle_bets.py)

Grades the stored bets in data/bets.json with grade_bets and prints one line per bet: the result, the reason, whether it is final and the score it was based on (guide). The sample bets cover a quarter-line handicap, a push, extra time, a shootout, a player prop, a cancelled match and a market that is not graded. Settlement needs a paid plan.

python settle_bets.py

Tips

  • Rate Limits: Be mindful of the API rate limits (5,000 requests/hour)
  • Error Handling: All examples use context managers for proper resource cleanup
  • Free Tier: Some features may be limited on the free tier (e.g., 2 bookmakers max)
  • Real Data: These examples use real API data, so results will vary

Need Help?