How georgedouzas/sports-betting works
Purpose and Entry Points
sports-betting is a Python package for acquiring sports statistics and odds, shaping them into modelling datasets, and evaluating scikit-learn-based betting strategies. It is consumed through Python, a command-line interface, or an MCP server for AI agents.
Primary entry points:
• Package/module execution: src/sportsbet/__init__.py, src/sportsbet/__main__.py
• CLI command routing: src/sportsbet/cli/_cli.py
• Agent-facing MCP server: src/sportsbet/mcp/_server.py
Data Acquisition and Source Boundary
The source layer defines provider abstractions and concrete adapters for sports results/statistics and bookmaker odds. It isolates provider-specific HTTP retrieval, source resolution, schema normalization, credentials, and bundled sample data from downstream modelling.
Key paths:
• src/sportsbet/sources/_base.py
• src/sportsbet/sources/_fetch.py
• src/sportsbet/sources/_resolver.py
Concrete integrations include Football-Data, EuroLeague, ESPN NBA, and The Odds API:
• src/sportsbet/sources/_football_data.py
• src/sportsbet/sources/_euroleague.py
• src/sportsbet/sources/_nba.py
• src/sportsbet/sources/_odds_api.py
External calls occur during extraction; The Odds API requires an environment-held API key. Packaged compressed CSVs support sample soccer sources under src/sportsbet/sources/data/.
Dataset Construction
DataLoader composes one statistics source and one odds source, expands a user-selected parameter grid (league/division/year), downloads and reconciles records, and produces aligned modelling outputs: features X, outcome labels Y, and odds O.
Core boundary and orchestration:
• src/sportsbet/dataloaders/_base.py
• src/sportsbet/dataloaders/_sourced.py
• src/sportsbet/_selection.py
Training extraction uses historical completed seasons; fixture extraction is a separate current-season request for upcoming events. This separation prevents the normal training/fixture overlap and allows a fitted bettor to score future fixtures with the same feature schema. Dataloaders are intended to be persisted after extraction to avoid repeat downloads or paid API use.
Betting Evaluation Engine
The evaluation layer wraps compatible scikit-learn estimators as bettors. It trains models against X, Y, and odds, compares predicted probability with offered prices to identify value bets, simulates bankroll/stake outcomes, and reports backtest metrics.
Core evaluator contracts and implementations:
• src/sportsbet/evaluation/_base.py
• src/sportsbet/evaluation/_classifier.py
• src/sportsbet/evaluation/_rules.py
Classifier bettors support multi-market outcome prediction; rule-based bettors provide non-estimator strategy logic. Evaluation consumes prepared datasets rather than contacting providers directly.
Backtesting and Model Selection
Time-aware backtesting and bettor-aware hyperparameter search sit above bettor implementations. They coordinate fold fitting/evaluation and can search both estimator parameters and betting-market selection.
Key paths:
• src/sportsbet/evaluation/_model_selection.py
• src/sportsbet/evaluation/_base.py
The principal runtime dependency is scikit-learn: callers supply estimators, pipelines, and CV splitters, while the package adds odds-aware betting semantics and financial metrics.
CLI and Persistence Workflow
The CLI mirrors the Python workflow: select sources and parameters, extract/save a dataloader, then backtest, fit/save a bettor, or produce bets from saved artifacts. It is therefore an orchestration boundary over the same dataloader and evaluation APIs, not a separate execution engine.
Command domains:
• src/sportsbet/cli/_data.py
• src/sportsbet/cli/_betting.py
• src/sportsbet/cli/_options.py
AI-Agent Surface and Delivery
The optional MCP runtime exposes library/CLI-equivalent operations to AI agents, with agent-oriented discovery and analysis capabilities:
• src/sportsbet/mcp/__init__.py
• src/sportsbet/mcp/_server.py
The project is packaged as typed Python (src/sportsbet/py.typed), distributed through PyPI, and documents its public Python, CLI, and agent interfaces under docs/interfaces/.
Main entry points: evaluation/_base.py Bettor contracts · _sourced.py DataLoader · _cli.py CLI router · sources/_base.py Provider contracts
Components 20
Entry surfaces
- Python package
src/sportsbet/__init__.py - Module execution
src/sportsbet/__main__.py - CLI router · Routes data and betting workflows.
src/sportsbet/cli/_cli.py - Data commands
src/sportsbet/cli/_data.py - Betting commands
src/sportsbet/cli/_betting.py
Source boundary
Provider-specific retrieval and normalization.
- Provider contracts
src/sportsbet/sources/_base.py - HTTP fetch
src/sportsbet/sources/_fetch.py - Source resolver
src/sportsbet/sources/_resolver.py - Sports data adapters · Football-Data, EuroLeague, and ESPN NBA adapters.
src/sportsbet/sources/_football_data.py - Odds API adapter · Uses an environment-held API key.
src/sportsbet/sources/_odds_api.py - Bundled sample CSVs
src/sportsbet/sources/data/England_1_2024_stats.csv.gz
Dataset construction
- Parameter grid · Expands league, division, and year requests.
src/sportsbet/_selection.py - DataLoader · Reconciles statistics and odds into X, Y, and O.
src/sportsbet/dataloaders/_sourced.py - Dataset contract
src/sportsbet/dataloaders/_base.py
Betting evaluation
- Bettor contracts
src/sportsbet/evaluation/_base.py - Classifier bettors · Predicts multi-market outcomes and value bets.
src/sportsbet/evaluation/_classifier.py - Rule bettors
src/sportsbet/evaluation/_rules.py - Backtesting and search · Coordinates time-aware folds and bettor-aware parameter search.
src/sportsbet/evaluation/_model_selection.py
Agent and delivery
- MCP server · Exposes discovery and analysis operations to AI agents.
src/sportsbet/mcp/_server.py - Interface documentation
docs/interfaces/index.md
Connections 22
- Python package → Module execution: supports execution
- Module execution → CLI router: starts
- CLI router → Data commands: routes
- CLI router → Betting commands: routes
- Data commands → DataLoader: extracts and saves
- Betting commands → Bettor contracts: backtests, fits, bets
- Source resolver → Provider contracts: resolves
- Provider contracts → HTTP fetch: retrieves through
- Sports data adapters → Provider contracts: implements
- Odds API adapter → Provider contracts: implements
- Bundled sample CSVs → Sports data adapters: supports sample sources
- Parameter grid → DataLoader: defines requests
- Source resolver → DataLoader: selects sources for
- DataLoader → Dataset contract: implements
- Dataset contract → Bettor contracts: provides X, Y, O
- Bettor contracts → Classifier bettors: specializes
- Bettor contracts → Rule bettors: specializes
- Backtesting and search → Bettor contracts: fits and evaluates
- MCP server → DataLoader: agent operations
- MCP server → Bettor contracts: agent operations
- Interface documentation → CLI router: documents
- Interface documentation → MCP server: documents